Friday, May 9, 2014

Manually Execute a Spring @Scheduled method

I have to admit I'm a little disappointed that there isn't an easy way to hook into Spring's @Scheduled jobs like there is with Quartz jobs.  I expected there to be some way to get the list of scheduled jobs but after digging through the ScheduledAnnotationBeanPostProcessor it doesn't look like they make that data visible.

So, here is a way to execute a method annotated with the @Scheduled annotation.  And, for the record, I don't like having to manually create Spring beans, loop through methods, or any of the other smelly things that are going on here.

The BaseAjaxResponse is simply a pojo that gets converted into json (see SpringMVC and jackson)

2 comments:

  1. Please, vote for this issue: https://jira.spring.io/browse/SPR-14562 to create an easy-way to do this.

    ReplyDelete
  2. Why not inject the bean with @Scheduled methods and just call them? What is the value of this approach?

    ReplyDelete