Reputation: 63
I am trying to implement a interface method annotated with @Scheduled
annotation with a cron expression. I am expecting the class that implements the interface and overrides the method should have the scheduler functionality from the interface but that's not the case? Can anyone explain me why? Is there another solution to achieve this functionality?
Interface:
@Component
public interface TestInterface {
@Scheduled(cron = "0 0/1 * 1/1 * *")
public void testScheduler();
}
Implementation Class:
@RestController
public class Controller implements TestInterface {
@Override
public void testScheduler() {
System.out.println("Test Scheduler implemented");
}
}
Upvotes: 4
Views: 2576
Reputation: 661
As noted in comments by M.Denium, the annotation is not inherited from the interface method. You need to add the annotation on the bean implementation as Spring will only scan the beans for the @Scheduled annotation.
Upvotes: 1