通过Property禁用Spring Scheduler任务 [英] Disable a Spring Scheduler Task via Property

查看:141
本文介绍了通过Property禁用Spring Scheduler任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Framework安排任务,并通过特定于环境的属性文件设置cron值。我正在寻找一种通过属性禁用此任务的方法,以便只有某些环境才能运行此任务。

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" />


推荐答案

您可以使用Spring环境配置文件(使用注释的示例使用xml的示例),因此您可以拥有不同的配置文件开发,测试,生产等。这些都是通过属性(spring.profiles.active)设置的。

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).

这篇关于通过Property禁用Spring Scheduler任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆