是否可以通过某些自定义属性指定固定的延迟间隔或cron间隔模式?目前,在我的配置中,在应用程序上下文xml文件上指定了固定的延迟间隔。但是,这个文件将打包在EAR中,对间隔的更改将需要重新部署应用程序。
以下是我的应用程序上下文文件:
<bean id="taskScheduler" class="org.springframework.scheduling.commonj.TimerManagerTaskScheduler">
<property name="timerManager" ref="timerManager" />
</bean>
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManager" ref="workManager" />
</bean>
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ref="transactionProcessingService" method="processTransactions" fixed-delay="30000"/>
<task:scheduled ref="transactionProcessingService" method="processOrderTransactions" fixed-delay="50000"/>
</task:scheduled-tasks>谢谢你的建议。
发布于 2013-08-12 15:12:32
您可以使用<util:properties />标记从文件中加载属性:
app.properties)
process_transactions=30000 process_order_transactions=3000properties标记从util命名空间加载它们(不要忘记到 namespace)
${variable}语法设置它们:
<任务:调度-任务scheduler="taskScheduler"> <任务:调度.固定延迟=“${process_transactions}”/><任务:计划.固定延迟=“${process_order_transactions}”/>编辑.正如@user320587所解释的那样,我们可以在Websphere中使用JVM自定义属性来重写应用程序属性值(并避免重新部署):
通过使用这一点以及systemPropertiesModeName属性在PropertyPlaceHolderConfigurer中可用,我们可以避免重新部署。我已经将属性值设置为Websphere中JVM自定义属性的一部分,并且在启动应用程序时会发生替换。因此,要更改区间值,我可以修改自定义属性值并重新启动应用程序。
发布于 2013-08-12 14:24:28
在应用程序上下文中添加以下内容
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:sample.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="order" value="0"/>
</bean>你的sample.properties文件
process_transactions = 30000
processOrder_transactions = 3000 用代码替换以下内容。
<task:scheduled-tasks scheduler="taskScheduler">
<task:scheduled ref="transactionProcessingService" method="processTransactions" fixed-delay="${process_transactions}"/>
<task:scheduled ref="transactionProcessingService" method="processOrderTransactions" fixed-delay="${processOrder_transactions}"/>
</task:scheduled-tasks>https://stackoverflow.com/questions/18189291
复制相似问题