我正在使用 Spring Framework 安排任务,并通过特定于环境的属性文件设置了 cron 值。我正在寻找一种通过属性禁用此任务的方法,以便只有某些环境才能运行此任务。
<task:scheduled-tasks>
<task:scheduled ref="theClass" method="theMethod" cron="${scheduler.cron}" />
</task:scheduled-tasks>
<bean id="theClass" class="com.test.TheClass" scope="prototype" />
最佳答案
您可以使用 Spring 环境配置文件 (example using annotations , example using xml ),因此您可以为开发、测试、生产等设置不同的配置文件。这些配置文件是通过属性 (spring.profiles.active) 设置的。
关于java - 通过属性禁用 Spring 调度程序任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16017215/