0

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.

Smriti mool
  • 139
  • 4
  • 11

1 Answers1

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
  • still scheduler is not executable. – Smriti mool May 02 '20 at 16:41
  • 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