I have a few methods annotated with
@Scheduled(fixedDelay = 6000)
private void myScheduledMethod(){
//do something
}
I also have a set of properties files where I configure environment specific values. For testing purposes I'd like the value of the delay to be configurable, ideally through a property in a properties file.
Since the value of fixedDelay
has to be a constant, I'm looking for a way to get this set from a properties file, but haven't found a way to do it yet.
I got stuck on the same issues but the best way to solve this now would be:
@Scheduled(fixedDelayString = "${my.delay.property}")
public void myScheduledMethod(){
// do something
}
It would be good to have this option, but I think it does not exist (the annotation is class-level, while the value would be injected when an instance is created).
In order to make this configurable use the xml namespace <task:
. Like the example from the spring docs:
<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="someObject" method="someMethod"
fixed-delay="${configuredDelay}"/>
</task:scheduled-tasks>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With