I have a Spring Boot application deployed in Tomcat 8. When the application starts I want to start a worker Thread in the background that Spring Autowires with some dependencies. Currently I have this :
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan
public class MyServer extends SpringBootServletInitializer {
public static void main(String[] args) {
log.info("Starting application");
ApplicationContext ctx = SpringApplication.run(MyServer.class, args);
Thread subscriber = new Thread(ctx.getBean(EventSubscriber.class));
log.info("Starting Subscriber Thread");
subscriber.start();
}
In my Docker test environment this works just fine - but when I deploy this to my Linux (Debian Jessie, Java 8) host in Tomcat 8 I never see the "Starting Subscriber Thread" message (and the thread is not started).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…