可以查看原文:https://www.cnblogs.com/gongchengshixiaobai/p/7868125.html 或者借鉴一下这里:https://angelbill3.iteye.com/blog/2371756 在service调用之前加上这个,就可以注入成功了 SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
@Service
public class HelloJob implements Job{
@Autowired
private HelloServiceImpl helloServiceImpl;
public void execute(JobExecutionContext context) throws JobExecutionException {
helloServiceImpl.sayHello();
}
}
@Service
public class HelloJob implements Job{
@Autowired
private HelloServiceImpl helloServiceImpl;
public void execute(JobExecutionContext context) throws JobExecutionException {
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
helloServiceImpl.sayHello();
}
}
本文介绍如何在Quartz定时任务中正确使用Spring Bean注入,通过在Job执行前调用SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext方法,确保了依赖注入的正确性。
6027

被折叠的 条评论
为什么被折叠?



