I'm new to Spring Boot, and I've got a Spring Boot application that seems to be ignoring the @PreDestroy annotation - when I run from command line or via Eclipse, I'm never seeing the @PreDestroy code being run when application is shutdown (e.g. via ctrl-c)
Code is below ...
Application.java:
@SpringBootApplication
public class Application {
@Autowired
private MessageProcessor messageProcessor;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@PostConstruct
public void init() {
messageProcessor.run();
}
}
Message Processor Config:
@Configuration
public class MessageProcessorConfiguration {
@Bean
public MessageProcessor messageProcessor() {
return new MessageProcessorImpl();
}
}
Message Processor:
public class MessageProcessorImpl implements MessageProcessor {
@Override
public void run() {
while (isActive()) {
…
}
}
@PreDestroy
public void shutdown() {
System.out.println("MessageProcessorImpl - shutting down");
}
}