配置Spring定时器的触发器的代码如下:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="cronTrigger_excute_must_value_enter" />
</list>
</property>
<!-- QuartzScheduler 延时启动,应用启动完后 QuartzScheduler 再启动 -->
<property name="startupDelay" value="20" />
<!-- 设置线程数,日志 -->
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.threadCount">1</prop>
<prop key="org.quartz.plugin.triggHistory.class">org.quartz.plugins.history.LoggingJobHistoryPlugin
</prop>
</props>
</property>
</bean>
<bean id="cronTrigger_excute_must_value_enter" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobDetail_excute_must_attr_enter" />
</property>
<property name="cronExpression">
<value>0 05 01 * * ? </value>
</property>
</bean>
<bean id="jobDetail_excute_must_value_enter"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="holdProductOperateRpcService" />
</property>
<property name="targetMethod">
<value>checkIsEnterMustAttr_noTrans</value>
</property>
</bean>
需要修改的地方是:
<property name="targetObject">
<ref bean="holdProductOperateRpcService" />
</property>
<property name="targetMethod">
<value>checkIsEnterMustAttr_noTrans</value>
</property>
targetObject 的值是要执行的service,targetMethod的值是:要执行service中的方法。