Some method has been Annotated with @Scheduled(fixedDelay=/.../)
, how can I get that value from the database?
already have needed service and repository, just not sure how to apply that value here.
Asked
Active
Viewed 2,717 times
2

Alchnemesis
- 479
- 8
- 23
-
Could be , will try this approach, thanks ! – Alchnemesis Jan 26 '18 at 07:50
1 Answers
6
You can define a bean in a @Configuration class somewhere else in your project which reads the delay rate from the database:
@Bean
public Long myFixedDelay() {
return myRepository.myDatabaseCallToGetDelay();
}
You can then reference this bean in your @Scheduled annotation using Spring EL:
@Scheduled(fixedDelayString = "#{@myFixedDelay}")

Plog
- 9,164
- 5
- 41
- 66
-
hmm, strange. I cannot call it that way, it requires for value to be (long) – Alchnemesis Jan 26 '18 at 07:49
-
1Oh I realised I made I mistake. To do it this way you need to use fixedDelayString instead of fixedDelay. Ill update my answer – Plog Jan 26 '18 at 09:17