在Spring 4.1应用程序中使用@Scheduled中的参数时出错

时间:2015-09-21 19:00:07

标签: spring spring-mvc spring-el spring-4

我有Spring 4.1 Application。我正在尝试根据属性文件中的值进行调度。我看过这个post。但我不想在@Scheduled

中使用以下EL方式
@Scheduled(fixedDelayString = "${my.fixed.delay.prop}")
public void readLog() {
        ...
}

这是我的班级。

public class MyService {

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

     public myService(){

     }

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

}

我收到此错误。

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

1 个答案:

答案 0 :(得分:0)

你做不到;它是注释工作方式的一个限制 - 注释中的字符串必须是常量(它们存储在类中,并且每个实例都可以不同)。

顺便说一下,${my.fixed.delay.prop}不是" EL",它是一个属性占位符。