|
@@ -1,43 +1,43 @@
|
|
|
package com.uas.report;
|
|
package com.uas.report;
|
|
|
|
|
|
|
|
-import org.springframework.boot.SpringApplication;
|
|
|
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
|
+import org.springframework.beans.BeansException;
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
+import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
|
|
+import org.springframework.boot.web.support.SpringBootServletInitializer;
|
|
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
|
|
|
+import org.springframework.context.ApplicationContextAware;
|
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
|
|
|
|
|
-import com.uas.report.schedule.service.TaskService;
|
|
|
|
|
-import com.uas.report.service.FileService;
|
|
|
|
|
import com.uas.report.util.ContextUtils;
|
|
import com.uas.report.util.ContextUtils;
|
|
|
|
|
+import com.uas.report.util.ReportUtils;
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 不使用spring boot内嵌的容器,部署在自定义Tomcat下时的程序入口
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author sunyj
|
|
|
|
|
+ * @since 2017年1月11日 下午5:18:41
|
|
|
|
|
+ */
|
|
|
@EnableTransactionManagement
|
|
@EnableTransactionManagement
|
|
|
@SpringBootApplication(scanBasePackages = "com.uas.report")
|
|
@SpringBootApplication(scanBasePackages = "com.uas.report")
|
|
|
@EnableWebMvc
|
|
@EnableWebMvc
|
|
|
-public class Application {
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
|
|
- SpringApplication application = new SpringApplication(Application.class);
|
|
|
|
|
- application.addListeners(new ContextUtils());
|
|
|
|
|
- application.run(args);
|
|
|
|
|
|
|
+public class Application extends SpringBootServletInitializer implements ApplicationContextAware {
|
|
|
|
|
|
|
|
- startTask();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 开启定时任务
|
|
|
|
|
- */
|
|
|
|
|
- public static void startTask() {
|
|
|
|
|
- SystemProperties systemProperties = ContextUtils.getBean(SystemProperties.class);
|
|
|
|
|
- if (systemProperties.isTaskAutoStart()) {
|
|
|
|
|
- FileService fileService = ContextUtils.getBean(FileService.class);
|
|
|
|
|
- TaskService taskService = ContextUtils.getBean(TaskService.class);
|
|
|
|
|
- fileService.newDeleteGeneratedFilesDailyTask(systemProperties.getDailyTaskHour(),
|
|
|
|
|
- systemProperties.getDailyTaskMinute(), systemProperties.getDailyTaskSecond());
|
|
|
|
|
|
|
+ private static Logger logger = Logger.getLogger(Application.class);
|
|
|
|
|
|
|
|
- // 开启定时任务
|
|
|
|
|
- if (!taskService.isStopped()) {
|
|
|
|
|
- taskService.stop();
|
|
|
|
|
- }
|
|
|
|
|
- taskService.start();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
|
|
|
|
+ // 程序入口
|
|
|
|
|
+ return builder.sources(Application.class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
|
|
+ // 注册spring上下文对象
|
|
|
|
|
+ ContextUtils.setApplicationContext(applicationContext);
|
|
|
|
|
+ logger.info("ApplicationContext registed");
|
|
|
|
|
+ // 开启定时任务
|
|
|
|
|
+ ReportUtils.startTask();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|