项目中需要继承Quartz框架。项目的环境是SSM框架,spring4.3,Quartz1.6版本,Intellij IDEA 2017.1
遇到的问题是:在quartz的Job中使用@Autowired自动注入service时候报错,报service为null。
原先代码如下:
public class XXXJob implements Job{
@AutoWired
XXXService xxxService;
@Override
public void execute(JobExecutionContext jobContext) throws JobExecutionException{
System.out.println(xxxService.getResult());
}
}
原来在非spring容器里面调用service的方法需要使用工具类获取service,ApplicationContext.getBean(“xxxService”)
然后写了工具类之后,又报出no bean named ‘xxxService’ available,没脾气,还是获取不到这个service,再去网上搜索Quartz的Job类中如何使用service,搜了一大堆相同的方法,比如什么配置AdaptableJobFactory,试了都没有用,还是报错。最后根据下面两个博客的内容整合之后,可以使用service了。
如何在Java Filter 中注入 Service
ServletContextLis