Smriti mool
Smriti mool

Reputation: 139

Scheduler as dependency in Spring Boot

I have two maven module 'client' and 'scheduler'. 'scheduler' module consists of code with Scheduler and runs each minute. When I run 'scheduler' module, it is working fine and scheduler executes each minute. Now, when I add it as a dependency in 'client' module, scheduler never runs.

Upvotes: 0

Views: 1539

Answers (1)

damjad
damjad

Reputation: 1280

Spring boot needs to know two things to run the scheduler. i.e The bean of the scheduler and config for enabling scheduling.

So, you need to add @EnableScheduling annotation to enable the schedulers and you need to register the scheduler bean in the spring context. For that, you can use

@ComponentScan (basePackages= {'current project package', 'scheduler package'}

or

@SpringBootApplication(scanBasePackages = {'current project package', 'scheduler package'}

Upvotes: 2

Related Questions