可以查看原文: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();
}
}