Deploying TaskScheduler with Spring

Can I insert an instance of TaskScheduler created by Spring?

I would like to schedule tasks programmatically and for this, I think I need to access TaskScheduler , but for some reason it was not found using Spring for auto-preparation.

 @Configuration @EnableScheduling public class MySpringConfig { } @Component public class MyClass implements InitializingBean { @Autowired private TaskScheduler taskScheduler; @Override public void afterPropertiesSet() throws Exception { ... } } 

Any idea?

Thanks!

+5
source share
1 answer
 @Configuration @EnableScheduling public class MySpringConfig { @Bean public TaskScheduler taskScheduler() { //org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler return new ThreadPoolTaskScheduler(); } } 

You can choose which implementation you like. ThreadPoolTaskScheduler is simpler as indicated in this link.

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html#scheduling-task-scheduler-implementations

+5
source

Source: https://habr.com/ru/post/1239047/


All Articles