我想通過外部配置文件禁用彈簧調度。我有配置文件設置,下面的示例中的任務會註銷以下內容。 INFO MainTaskScheduler:36 - scheduled task: Update converted bookings false.
因此,大多數情況下,那裏。禁用與屬性文件的調度
我希望實現的是不必在每個任務方法內部放置邏輯來確定是否已啓用調度屬性。
所以這樣的事情在我的配置文件(這是無效代碼) @EnableScheduling(${enable.scheduling})
我的工作片段
AppConfiguration
@Configuration
@EnableTransactionManagement
@EnableScheduling
@ComponentScan(/*etc*/})
public class AppConfiguration {
}
MainTaskScheduler
個@Component
public class MainTaskScheduler {
private Logger log = LoggerFactory.getLogger(getClass());
@Value("${enable.scheduling}")
private Boolean enableScheduling;
@Scheduled(fixedRate=300) // every 5 minutes -- check if any existing quotes have been converted to bookings
public void updateConvertedBookings() {
log.info("scheduled task: Update converted bookings "+enableScheduling);
// logic for class here
}
}
application.properties
enable.scheduling=false
使用配置文件。爲'@ EnableScheduling'創建一個單獨的'@ Configuration'類,該類僅在特定配置文件中啓用。 – 2015-03-25 12:02:59