如题,常规@Autowired是注入不生效的,需要通过实现ApplicationContextAware接口,
重写方法SetApplicationContext,
通过这个方法,可以获取到ApplicationContext上下对象,
根据上下文对象可以轻松获取到容器中注册的bean
getBean(String name)获取,bean的名字不是类名小写开头,获取不到,
改成使用class来获取即可
直接上代码
@Component("multiPreDeal")
public class MultiPreDeal implements ExecutionListener , ApplicationContextAware {
private static ApplicationContext applicationContext;
//注入不了
// @Autowired
// protected RepositoryService repositoryService;
@Override
public void notify(DelegateExecution delegateExecution) {
RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext1) throws BeansException {
applicationContext = applicationContext1;
}
}


