2013-04-15 34 views
4

我使用Spring Framework調度任務,並通過特定於環境的屬性文件設置了cron值。我正在尋找一種方法來通過屬性禁用此任務,以便只有特定的環境才能執行此任務。通過屬性禁用Spring Scheduler任務

<task:scheduled-tasks> 
<task:scheduled ref="theClass" method="theMethod" cron="${scheduler.cron}" /> 
</task:scheduled-tasks> 

<bean id="theClass" class="com.test.TheClass" scope="prototype" /> 

回答

4

你可以使用Spring環境型材(example using annotationsexample using xml),所以你可以有不同的配置文件用於開發,測試,生產等,這些設備通過屬性(spring.profiles.active設置)。

+0

我們目前在[MutablePropertySources]中使用Spring [ConfigurableEnvironment](http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/core/env/ConfigurableEnvironment.html) (http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/core/env/MutablePropertySources.html)以處理特定於環境的值。有沒有辦法做到這一點,而不必註釋我的課堂?理想情況下,我希望嚴格在Spring配置和Java代碼之外進行配置,以維護當前約定。 – Andrew

+0

您可以使用XML來配置配置文件。查看我剛添加的第二個鏈接。 – Luciano