I have a minimal Spring (not Spring Boot) application which has a scheduled method, but the context is closed before the task is triggered.
@Configuration
@EnableScheduling
public class Main {
@Bean
public TaskScheduler scheduler() {
return new ThreadPoolTaskScheduler();
}
@Scheduled(cron = "0 * * * * *")
public void run() {
System.out.println("tick"); // Never happens
}
public static void main(final String... args) {
try (GenericApplicationContext ctx = new AnnotationConfigApplicationContext(Main.class)) {
ctx.start();
}
}
}
How should I prevent context from closing?