0

I have Spring 4.1 Application. I am trying to schedule based on value from property file. I have read this post. But I do not want the following way of EL inside @Scheduled

@Scheduled(fixedDelayString = "${my.fixed.delay.prop}")
public void readLog() {
        ...
}

Here is my class.

public class MyService {

    @Value("${timerInMilliSeconds: 60000}")
    private long timerinMilliSeconds;

     public myService(){

     }

    @Scheduled(fixedRate = timerinMilliSeconds)
        public void myTimer() {
            //do stuff
        }

}

I get this error.

The value for annotation attribute Scheduled.fixedRate must be a constant expression

Community
  • 1
  • 1
brain storm
  • 30,124
  • 69
  • 225
  • 393

1 Answers1

0

You can't do that; it's a limitation of the way annotations work - Strings in annotations have to be constants (they are stored in the class and can't be different for each instance).

By the way ${my.fixed.delay.prop} is not "EL", it's a property placeholder.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179