Spring @ Planned Injection Delay Time

I have several methods annotated with

@Scheduled(fixedDelay = 6000) private void myScheduledMethod(){ //do something } 

I also have a set of property files where I configure environment-specific values. For testing purposes, I would like the delay value to be configured, ideally, through a property in the properties file.

Since the fixedDelay value must be constant, I am looking for a way to get this set from the properties file, but have not yet found a way to do this.

+7
java spring quartz-scheduler
source share
2 answers

I am stuck with the same problems, but the best way to solve this is now:

 @Scheduled(fixedDelayString = "${my.delay.property}") public void myScheduledMethod(){ // do something } 
+6
source share

It would be nice to have this parameter, but I think it does not exist (the annotation is a class, and the value will be entered when creating the instance).

To do this configuration, use the xml <task: namespace. As an example from spring docs :

 <task:scheduled-tasks scheduler="myScheduler"> <task:scheduled ref="someObject" method="someMethod" fixed-delay="${configuredDelay}"/> </task:scheduled-tasks> 
+5
source share

All Articles