你写了定时任务的配置文件了吗?spring-scheduler.xml?
这是我用过的写法
希望对你有帮助
在网上参考了大量方法,试过了,用到 AdaptableJobFactory这个类。
自定义一个类:
Java code?public class JobFactory extends AdaptableJobFactory {
@Autowired private AutowireCapableBeanFactory capableBeanFactory; @Override protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { // 调用父类的方法 Object jobInstance = super.createJobInstance(bundle); System.out.println("capableBeanFactory----------" + capableBeanFactory); // 进行注入 capableBeanFactory.autowireBean(jobInstance); return jobInstance; }}
然后在spring中配置:
XML/HTML code?
继承ApplicationContextAware的类和启动类放一块试试