简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM