码迷,mamicode.com
首页 > 其他好文 > 详细

Quartz的job中注入的services接口为空的解决办法

时间:2017-04-12 19:54:30      阅读:385      评论:0      收藏:0      [点我收藏+]

标签:uart   属性   oid   account   调度   etl   throws   net   return   

自己重新定义一个类继承AdaptableJobFactory类

public class JobFactory extends AdaptableJobFactory {  
    @Autowired  
    private AutowireCapableBeanFactory capableBeanFactory;  
  
    @Override  
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {  
        //调用父类的方法  
        Object jobInstance = super.createJobInstance(bundle);  
        //进行注入  
        capableBeanFactory.autowireBean(jobInstance);  
        return jobInstance;  
    }  
}  

在sprig配置文件中配置

    <bean id="jobFactory" class="com.ka.common.quartz.JobFactory"></bean>
    
    <!-- 调度器 -->
    <bean name="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    	<property name="jobFactory" ref="jobFactory"></property>
       	<!-- 通过applicationContextSchedulerContextKey属性配置spring上下文 -->    
        <property name="applicationContextSchedulerContextKey">    
            <value>applicationContext</value>    
        </property>   
    </bean>

在job中使用

public class QuartzTaskMeetingNoticeHandler implements Job {
	protected Logger log = LoggerFactory.getLogger(getClass());

	@Resource(name = "AdminJournalServices")
	protected IAdminJournalServices mIAdminJournalServices;
	@Resource(name = "AdminAccountServices")
	protected IAdminAccountServices mIAdminAccountServices;

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		log.debug("-------------------获取调度任务 start--------------------");
	}
}

 

引用参考:http://blog.csdn.net/irabbit0708/article/details/52023437

Quartz的job中注入的services接口为空的解决办法

标签:uart   属性   oid   account   调度   etl   throws   net   return   

原文地址:http://www.cnblogs.com/GodBug/p/6700727.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!