Spring中 Quartz 调度程序 scheduler JobDetailBean 注入 Service

在Spring中使用Quartz, IOC注入Service方法有点麻烦.和大家分享一个我的经验.
主要用到的是jobDataAsMap,其实它就一个Map,key是注入bean的名字.
传入的Value是一个Service的引用.

<bean name="transferJob" class="org.springframework.scheduling.quartz.JobDetailBean">
		<property name="jobClass" value="com.amssy.scheduler.TransferJob" />
		<property name="jobDataAsMap">
			<map>
				<entry key="customerService" value-ref="customerService"/>
				<entry key="orderService" value-ref="orderService"/>
			</map>
		</property>
	</bean>


<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail" ref="transferJob" />
		<property name="cronExpression" value="0 * * ? * * 2010" />
</bean>
	
<bean id="start" lazy-init="false" 
			class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="cronTrigger" />
			</list>
		</property>
</bean>

你可能感兴趣的:(java,spring,bean,quartz,IOC)