I'm using spring 5 scheduler in my web app & I need to set my fixedrate at run time, so I'm using ServletContextListener with @WebListener
annoated. In servletcontext class I'm using TaskScheduler scheduler.setFixedAtRate(<Runnable>, <Get value from DB>, <time period>);
I had annotated my service class Scheduler configured successfully & executing on time. But problem is getting @Autowired
my services in scheduled class, they are not binding. While other business logic @Autowired
working successfully.
It's because ServlerContextListener mostly isn't managed by Spring. It's well explained in here: Spring @Autowired annotation doesn't work in Java TimerTask
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.