转自CSDN :https://blog.csdn.net/Laiguanfu/article/details/89366193
第一步创建springUtil类
@Component
public class SpringUtil implements ApplicationContextAware{
/**
* 当前IOC
*
*/
private static ApplicationContext applicationContext;
/**
* 设置applicationContext
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/**
* 从当前IOC获取bean
*/
public static <T> T getObject(Class<T> clazz){
return applicationContext.getBean(clazz);
}
public static void showClass(){
String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
for(String beanDefinitionName : beanDefinitionNames){
System.out.println(beanDefinitionName);
}
}
}
第二步直接使用
public class FaultListener implements TaskListener{
/*
* @Autowired ActivitiTaskServiceImpl activityDemoServiceImpl;
*/
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void notify(DelegateTask delegateTask) {
//这是service
ActivitiTaskServiceImpl activitiTaskServiceImpl=SpringUtil.getObject(ActivitiTaskServiceImpl.class);
activitiTaskServiceImpl.getHell();
System.out.println("getExecutionId="+delegateTask.getExecutionId() + "ProcessInstanceId="+delegateTask.getProcessInstanceId()+
"assignee"+delegateTask.getAssignee()+" "+" name="+delegateTask.getName()+
" 下一活动节点 getEventName= "+delegateTask.getEventName()+" 下一任务id="+delegateTask.getId());
}
}
//service类就不展示了,很简单,在你的service类中加如@Service注解即可。
以上步骤可以直接获取service,dao是通过service调用,所以把dao返给service即可