我試圖從環境變量設置註釋值:從環境變量中設置一個註解屬性?
@Configuration
@ComponentScan
@EnableAutoConfiguration
@EnableScheduling
class Application {
@Scheduled(cron = "${DB_CRON}")
def void schedule() {
...
}
public static void main(String... args) {
SpringApplication.run(Application, args)
}
...
}
不過,我得到以下編譯時錯誤:
Attribute 'cron' should have type 'java.lang.String'; but found type 'java.lang.Object' in @org.springframework.scheduling.annotation.Scheduled
是否有可能設置註釋這種方式,還是我需要使用其他技術,例如在屬性文件中設置值?
這更接近於一個工作解決方案,但我現在遇到了一個運行時錯誤:'線程中的異常「主要」groovy.lang.MissingMethodException:沒有方法的簽名:static org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.setSystemPropertiesMode( )適用於參數類型:(java.lang.Integer)values:[2] 可能的解決方案:setSystemPropertiesMode(int),setSystemPropertiesModeName(java.lang.String)'。 **注意:**'snowch $ echo「$ db_cron」' - >'0 19 21 * * *' –
請編輯該問題,提供完整的錯誤信息並跟蹤代碼中的行號和相關行數 – cfrick
還有其他拋出此錯誤的代碼。我已經刪除了這些代碼,現在所有代碼都在運行。非常感謝! –