package com.sig.ggits.tsinfo.server; import com.its.common.spring.SpringUtils; import com.sig.ggits.tsinfo.server.service.TsinfoFileWatcherService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.Banner; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.ApplicationPidFileWriter; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.event.ContextClosedEvent; import org.springframework.scheduling.annotation.EnableAsync; import java.text.SimpleDateFormat; import java.util.Date; @Slf4j @EnableAsync @Configuration @SpringBootApplication//(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) @ComponentScan(basePackages = {"com.its.common.spring", "com.sig.ggits.tsinfo.server.config", "com.sig.ggits.tsinfo.server"}) public class GgitsTsinfoServerApplication implements CommandLineRunner, ApplicationListener, InitializingBean, DisposableBean { public static final String APPLICATION_NAME = "ggits-tsinfo-server"; public static void main(String[] args) { SpringApplication application = new SpringApplicationBuilder() .sources(GgitsTsinfoServerApplication.class) .listeners(new ApplicationPidFileWriter("./conf/" + APPLICATION_NAME + ".pid")) .build(); application.setBannerMode(Banner.Mode.OFF); application.run(args); } @Override public void run(String... args) throws Exception { SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); log.info(""); log.info(""); log.info("************************************************************************************"); log.info("** **"); log.info("** UTIC Signal System **"); log.info("** GGITS Traffic Signal State Gather Server Program. **"); log.info("** **"); log.info("** [ver.1.0] **"); log.info("** startup: {}", sdfDate.format(new Date())); log.info("** HOME: {}", System.getProperty("user.home")); log.info("************************************************************************************"); TsinfoFileWatcherService tsinfoFileWatcherService = SpringUtils.getBean(TsinfoFileWatcherService.class); tsinfoFileWatcherService.start(); } public void terminateApplication() { } @Override public void onApplicationEvent(ContextClosedEvent event) { SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), event); terminateApplication(); } @Override public void destroy() throws Exception { log.error("Application destroy"); } @Override public void afterPropertiesSet() throws Exception { } }