0

I've got an Async method which is scheduled to run once a day:

@Component
public class MyClass {

    //myCronProperty set to "0 25 20 * * *" in application.properties
    @Scheduled(cron="{myCronProperty}")
    @Async
    @Override
    public void doDailyTask() {
        //Do work here
    }
}

Is there a way of triggering doDailyTask() for testing purposes when the application is already running, perhaps by doing something clever with Groovy and reflection?

I figure I can always tweak the cron property to 1 minute in the future in my application.properties file, and then restart the application - but just wondered if there was a smarter method?

Ben
  • 355
  • 2
  • 11

1 Answers1

0

You should be able to simply inject the component into another class, for example a @RestController, and invoke the doDailyTask() method on it there.

ck1
  • 5,243
  • 1
  • 21
  • 25