Commit 7af640e7 authored by 张永's avatar 张永

11

parent befc2d8f
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<properties> <properties>
<start-class>com.egolm.shop.ShopApplication</start-class> <start-class>com.egolm.shop.ShopApplication</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties> </properties>
<parent> <parent>
...@@ -109,6 +109,11 @@ ...@@ -109,6 +109,11 @@
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>
...@@ -123,9 +128,10 @@ ...@@ -123,9 +128,10 @@
<artifactId>druid-spring-boot-starter</artifactId> <artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.20</version> <version>1.1.20</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.microsoft.sqlserver</groupId> <groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId> <artifactId>mssql-jdbc</artifactId>
<version>9.4.0.jre8</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
......
package com.egolm.shop; package com.egolm.shop;
import java.util.TimeZone;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableAsync(proxyTargetClass=true) @EnableAsync(proxyTargetClass=true)
...@@ -17,15 +23,22 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -17,15 +23,22 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement @EnableTransactionManagement
public class ShopApplication { public class ShopApplication {
private static Logger logger = LoggerFactory.getLogger(ShopApplication.class);
private static ApplicationContext applicationContext; private static ApplicationContext applicationContext;
public static void main(String[] args) { public static void main(String[] args) {
System.setProperty("java.io.tmpdir", "temp"); try {
applicationContext = SpringApplication.run(ShopApplication.class, args); System.setProperty("java.io.tmpdir", "temp");
}catch(Exception e) {
logger.info("docker 容器中运行。。。。");
System.setProperty("java.io.tmpdir", "/data/temp"); //容器内使用这种
}finally {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
applicationContext = SpringApplication.run(ApplicationContext.class, args);
}
} }
public static ApplicationContext getApplicationContext() { public static ApplicationContext getApplicationContext() {
return applicationContext; return applicationContext;
} }
...@@ -37,9 +50,8 @@ public class ShopApplication { ...@@ -37,9 +50,8 @@ public class ShopApplication {
public static <T> T getBean(Class<T> clazz){ public static <T> T getBean(Class<T> clazz){
return getApplicationContext().getBean(clazz); return getApplicationContext().getBean(clazz);
} }
public static <T> T getBean(String name, Class<T> clazz){ public static <T> T getBean(String name, Class<T> clazz){
return getApplicationContext().getBean(name, clazz); return getApplicationContext().getBean(name, clazz);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment