Reputation: 1955
I created an abstract class like this:
abstract class ScheduledProcess {
abstract List<String> fetchNewContent()
abstract List<String> cron()
//This SPeL doesn't work just stating what kind of expression I'm looking for
@Scheduled(cron='#{this.cron()}')
void persistContent(){
doSomeStuffWithContent(fetchNewContent())
}
}
My goal is to do not repeat myself having to implement the @Scheduled
method in all subclasses. The cron()
method returns the specific subclass cron expression. However I'm not finding a way to pass to the annotation the cron value. Maybe I'm just looking at this problem the wrong way.
Upvotes: 5
Views: 2958
Reputation: 8324
I think this is now possible (Spring 4.3.0) you can see it in the issue.
https://jira.spring.io/browse/SPR-13625
If you are using another Spring version you can write your own beanpostprocessor. You can see an example in the answer given by quantum here
Injecting externalized value into Spring annotation
Upvotes: 2
Reputation: 174564
You can't use SpEL there, only property placeholders ${...}
.
Upvotes: 0