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.
Asked
Active
Viewed 941 times
0
-
2Probably you have to enable scheduling in your main application and do a component scan for the package of the scheduler. – damjad May 02 '20 at 15:00
-
1@chuckskull Why don't you add this as the answer? – Simon Martinelli May 02 '20 at 15:05
-
@SimonMartinelli It's been two years since I last touched spring boot. So, memory is a bit rusty. – damjad May 02 '20 at 15:17
1 Answers
2
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'}

damjad
- 1,252
- 1
- 15
- 24
-
-
Also, if I were to create a constructor or Autowire any classes in scheduler package, do I have to create a bean passing each constructors in client module? – Smriti mool May 02 '20 at 16:57
-
@Smritimool you can check the list of all beans registered in the context and see if the required is there or not: https://stackoverflow.com/a/24039278/8084588 Also, make sure that the dependency is properly added in the classpath. – damjad May 02 '20 at 17:15
-
@Smritimool Please also post your annotations used in the runner class. – damjad May 02 '20 at 17:22