2015-09-21 18 views
0

我有Spring 4.1 Application。我正在嘗試根據屬性文件的值進行計劃。我已閱讀此post。但我不希望裏面@Scheduled在彈簧4.1應用程序中使用@Scheduled參數時出錯

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

這裏是我的課EL下列方式。

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

回答

0

你不能那樣做;它是註釋工作方式的一個限制 - 註釋中的字符串必須是常量(它們存儲在類中,每個實例不能不同)。

順便說一句${my.fixed.delay.prop}不是「EL」,它是一個屬性佔位符。

相關問題