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

自己重新定义一个类继承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配置文件中配置

    
    
    
    
    	
       	    
            
            applicationContext    
           
    

在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

转载于:https://www.cnblogs.com/GodBug/p/6700727.html

你可能感兴趣的:(Quartz的job中注入的services接口为空的解决办法)