- 建立MyJobFactory Class
- public class MyJobFactory extends AdaptableJobFactory{
- //这个对象Spring会帮我们自动注入进来,也属于Spring技术范畴.
- @Autowired
- private AutowireCapableBeanFactory capableBeanFactory;
- protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
- //调用父类的方法
- Object jobInstance = super.createJobInstance(bundle);
- //进行注入,这属于Spring的技术,不清楚的可以查看Spring的API.
- capableBeanFactory.autowireBean(jobInstance);
- return jobInstance;
- }
- }
2. 加入
<bean id="jobFactory" class="dim.job.MyJobFactory"></bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<bean id="jobFactory" class="dim.job.MyJobFactory"></bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobFactory" ref="jobFactory"></property>
</bean>
沒有留言:
張貼留言