Disable a Spring Scheduler Task via Property

那年仲夏 提交于 2019-12-01 21:26:55

问题


I am scheduling a task using Spring Framework and have a cron value set through an environment specific property file. I am looking for a way to disable this task through a property so that only certain environments run this task.

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

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

回答1:


You can use Spring environment profiles (example using annotations, example using xml), so you can have different profiles for development, testing, production, etc. And these are set via properties (spring.profiles.active).



来源:https://stackoverflow.com/questions/16017215/disable-a-spring-scheduler-task-via-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!