Reputation: 452
I have a scheduled task class with @Component annotation. I have this successfully pulling data from the .properties file for the delay time, but I'd like to use that same value later INSIDE the method.
@Scheduled(fixedDelayString = "${mypropvalue}")
public void doScheduledTask () throws IOException
{
// do some stuff
log.info("The doScheduledTask finished at {} ", dateFormat.format(new Date()));
log.info("The next task will run in {} ms", @Value("${mypropvalue}"));
}
The @Value on the last line has a compile error saying "Annotations are not allowed here". How can I get that value again from inside the method? And since I am using @Scheduled, I cannot pass in that @Value as a parameter.
Upvotes: 0
Views: 326
Reputation: 174504
Add it as a field
@Value("${mypropvalue}
private long fixedDelay
then
this.fixedDelay
within your method.
Upvotes: 1