Adarsh Pandey
Adarsh Pandey

Reputation: 57

Scheduling not working for rest calls in spring boot microservice

I have a spring boot microservice which contains a method which I need to run every Sunday so I used @Scheduled annotation on the method and @EnableScheduling annotation in the configuration class.The method annotated with @Scheduling calls up a other method which in turn calls up a client class where response is fetched by making a rest call to a other microservice but the rest call step is not executing and it throws error when I use scheduled annotation when I trigger the method from controller it works fine but for scheduler the rest call is not happening.

Upvotes: 0

Views: 819

Answers (1)

daemonThread
daemonThread

Reputation: 1044

Please share your code and the error you are getting. I am sharing an example for your reference.

@PostMapping(value = "/runWeeklyJob", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @Scheduled(cron =  "0 0 1 ? * SUN *")
    public ResponseEntity<?> runWeeklyJob() throws Exception {
        //processing
        return responseEntity;
    }

Upvotes: 1

Related Questions