protected ServiceTask createServiceTask(String id, String name, String ref) {
ServiceTask serviceTask = new ServiceTask();
serviceTask.setId(id);
serviceTask.setName(name);
serviceTask.setImplementation(ref);
serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
return serviceTask;
}
public class ServiceTaskDelegate implements JavaDelegate {
@Autowired
private RepositoryService repositoryService;
@Override
public void execute(DelegateExecution delegateExecution) {
System.out.println("service task execute");
System.out.println(repositoryService);
}
}
当我使用ImplementationType = ImplementationType.IMPLEMENTATION_TYPE_CLASS可以 ,但repositoryService == null
所以我使用ImplementationType = ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION 扔掉
Caused by: org.activiti.engine.ActivitiIllegalArgumentException: Delegate expression com.test.activiti.ServiceTaskDelegate did neither resolve to an implementation of interface org.activiti.engine.impl.delegate.ActivityBehavior nor interface org.activiti.engine.delegate.JavaDelegate
springboot2.0 / activit6.0
答案 0 :(得分:0)
答案 1 :(得分:0)
于是我还是用了ImplementationType.IMPLEMENTATION_TYPE_CLASS 但是在获取bean的方式上不用@autowired或更自己写了getBean的方法代码如下:
@Component
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext applicationContext = null;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if(SpringUtils.applicationContext == null){
SpringUtils.applicationContext = applicationContext;
}
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static Object getBean(String name){
return getApplicationContext().getBean(name);
}
public static <T> T getBean(Class<T> clazz){
return getApplicationContext().getBean(clazz);
}
public static <T> T getBean(String name, Class<T> clazz){
return getApplicationContext().getBean(name, clazz);
}
}
这样我就可以通过RuntimeService runtimeService = SpringUtils.getBean(RuntimeService.class);获取RuntimeService