ItsOpServerApplication.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package com.its.op;
  2. import com.its.op.config.*;
  3. import com.its.op.entity.its.unit.TbUnitSyst;
  4. import com.its.op.global.UnitSystManager;
  5. import com.its.op.xnetudp.CenterCommUdpServer;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.beans.factory.DisposableBean;
  8. import org.springframework.beans.factory.InitializingBean;
  9. import org.springframework.boot.Banner;
  10. import org.springframework.boot.CommandLineRunner;
  11. import org.springframework.boot.SpringApplication;
  12. import org.springframework.boot.autoconfigure.SpringBootApplication;
  13. import org.springframework.boot.builder.SpringApplicationBuilder;
  14. import org.springframework.boot.context.ApplicationPidFileWriter;
  15. import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  16. import org.springframework.context.ApplicationListener;
  17. import org.springframework.context.annotation.Configuration;
  18. import org.springframework.context.annotation.EnableAspectJAutoProxy;
  19. import org.springframework.context.event.ContextClosedEvent;
  20. import org.springframework.scheduling.annotation.EnableAsync;
  21. import org.springframework.web.bind.annotation.CrossOrigin;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;
  24. @Slf4j
  25. //@EnableJpaAuditing // JPA Auditing 활성화
  26. @EnableAspectJAutoProxy
  27. @EnableAsync
  28. @Configuration
  29. @SpringBootApplication
  30. /*@ComponentScan(basePackages = {
  31. "com.its.op.config",
  32. "com.its.op.dao.repository.its",
  33. "com.its.op.dao.repository.bis",
  34. "com.its.op.dao.repository.utis",
  35. "com.its.op.controller.*"
  36. })*/
  37. //@ComponentScan("com.its")
  38. //@MapperScan({"com.its.op.dao.mapper.its", "com.its.op.dao.mapper.bis", "com.its.op.dao.mapper.utis"})
  39. @CrossOrigin("*")
  40. public class ItsOpServerApplication extends SpringBootServletInitializer implements CommandLineRunner, ApplicationListener<ContextClosedEvent>, InitializingBean, DisposableBean {
  41. private static final String applicationName = "its-op-server";
  42. public ItsOpServerApplication() {
  43. super();
  44. setRegisterErrorPageFilter(false);
  45. }
  46. @Override
  47. protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  48. return builder.sources(ItsOpServerApplication.class);
  49. }
  50. public static void main(String[] args) {
  51. SpringApplication application = new SpringApplicationBuilder()
  52. .sources(ItsOpServerApplication.class)
  53. .listeners(new ApplicationPidFileWriter("./conf/" + applicationName + ".pid"))
  54. .build();
  55. application.setBannerMode(Banner.Mode.OFF);
  56. application.run(args);
  57. }
  58. @Override
  59. public void run(String... args) {
  60. ApplicationConfig applicationConfig = (ApplicationConfig) AppUtils.getBean(ApplicationConfig.class);
  61. log.info("");
  62. log.info("");
  63. log.info("************************************************************************************");
  64. log.info("** **");
  65. log.info("** Intelligent Traffic System **");
  66. log.info("** Intelligent Traffic System Common Operating Server. **");
  67. log.info("** **");
  68. log.info("** [ver.1.0] **");
  69. log.info("** process: {}", applicationConfig.getId());
  70. log.info("** startup: {}", applicationConfig.getBootingDateTime());
  71. log.info("************************************************************************************");
  72. CenterCommUdpServer centerCommUdpServer = (CenterCommUdpServer)AppUtils.getBean(CenterCommUdpServer.class);
  73. centerCommUdpServer.run();
  74. // VdsCommClientService vdsCommClientService = (VdsCommClientService)AppUtils.getBean(VdsCommClientService.class);
  75. // vdsCommClientService.run();
  76. VmsServerConfig vmsServerConfig = (VmsServerConfig)AppUtils.getBean(VmsServerConfig.class);
  77. TbUnitSyst vmsServer = UnitSystManager.get(vmsServerConfig.getProcessId());
  78. if (vmsServer != null) {
  79. vmsServerConfig.setIpAddress(vmsServer.getSystIp1().trim());
  80. vmsServerConfig.setPort(Integer.parseInt(vmsServer.getPrgmPort().trim()));
  81. }
  82. VdsServerConfig vdsServerConfig = (VdsServerConfig)AppUtils.getBean(VdsServerConfig.class);
  83. TbUnitSyst vdsServer = UnitSystManager.get(vdsServerConfig.getProcessId());
  84. if (vdsServer != null) {
  85. vdsServerConfig.setIpAddress(vdsServer.getSystIp1().trim());
  86. vdsServerConfig.setPort(Integer.parseInt(vdsServer.getPrgmPort().trim()));
  87. }
  88. RseServerConfig rseServerConfig = (RseServerConfig)AppUtils.getBean(RseServerConfig.class);
  89. TbUnitSyst rseServer = UnitSystManager.get(vdsServerConfig.getProcessId());
  90. if (rseServer != null) {
  91. rseServerConfig.setIpAddress(rseServer.getSystIp1().trim());
  92. rseServerConfig.setPort(Integer.parseInt(rseServer.getPrgmPort().trim()));
  93. }
  94. CctvServerConfig cctvServerConfig = (CctvServerConfig)AppUtils.getBean(CctvServerConfig.class);
  95. TbUnitSyst cctvServer = UnitSystManager.get(vdsServerConfig.getProcessId());
  96. if (cctvServer != null) {
  97. cctvServerConfig.setIpAddress(cctvServer.getSystIp1().trim());
  98. cctvServerConfig.setPort(Integer.parseInt(cctvServer.getPrgmPort().trim()));
  99. }
  100. applicationConfig.setStartSchedule(true);
  101. }
  102. @Override
  103. public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
  104. // shutdown.....
  105. SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  106. log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent.toString());
  107. }
  108. @Override
  109. public void destroy() {
  110. }
  111. @Override
  112. public void afterPropertiesSet() {
  113. }
  114. }