Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Scheduler not working when used on the Interface method

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");   
    }

}
like image 935
Bhagath Avatar asked Mar 05 '26 20:03

Bhagath


1 Answers

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.

like image 136
Tatenda Zifudzi Avatar answered Mar 08 '26 08:03

Tatenda Zifudzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!