我正在尝试使用 Spring 托管流程引擎使用 Activiti 5.5 使工作流正常工作,但遇到了一些麻烦。
我的工作流程中有一个 ServiceTask 解析为 Spring Managed bean。它看起来像这样:
<serviceTask id="springTask1" name="BeanTest" activiti:delegateExpression="${taskBean}"></serviceTask>
我不是通过代码启动该过程,该过程是通过 activti-rest api 或表单启动的。如何从 bean 内部获取执行此任务的上下文,以便我可以添加可以在以后的任务(例如电子邮件)中引用的流程变量。我尝试查看 Activiti 5.5 附带的 spring 示例,但我看不出我的示例与示例有何不同。我正在实现与 spring 示例显示的相同的 JavaDelegate 接口。
这是我的代码:
public class GetBeanTest implements JavaDelegate {
private ContactService contactService;
public GetBeanTest() {
super();
}
public String getContactName(String contactName) throws Exception {
String retVal= "unknown";
if(contactService == null){
System.out.println("Bean was null!");
}else{
System.out.println("Bean is valid!");
List<Contact> contacts= contactService.getContacts();
System.out.println("There are " + contacts.size() +" in the contact list.");
for (Contact contact : contacts) {
if(contact.getName().equalsIgnoreCase(contactName)){
System.out.println("Found the contact! " + contactName );
retVal= contact.getEmail();
}
}
}
return retVal;
}
public void setContactService(ContactService contactService) {
this.contactService = contactService;
}
@Override
public void execute(DelegateExecution execution) throws Exception {
System.out.println("+++++++++++++ in execute ++++++++++++++++");
System.out.println("Event Name: " + execution.getEventName());
System.out.println("ID: " + execution.getId());
System.out.println("Process Instance ID: " + execution.getProcessInstanceId());
Set<String> varNames= execution.getVariableNames();
for (String string : varNames) {
System.out.println("Varible Named " + string + " exists");
if(string.equalsIgnoreCase("contactName")){
String contactName= (String) execution.getVariable(string);
getContactName(contactName);
}else{
System.out.println("unable to find contact name.");
}
}
}
}
这是弹簧配置(为简洁起见,省略了无聊的部分):
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<!--Dao Beans -->
<bean id="contactDao" class="org.psc.database.dao.jpa.ContactDaoImpl"/>
<!-- Service Beans -->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
<bean id="contactService" class="org.psc.service.impl.ContactServiceImpl">
<property name="contactDao" ref="contactDao"/>
</bean>
<bean id="contact" class="org.psc.bpmn.tasks.Contact"/>
<bean id="taskBean" class="org.psc.bpmn.examples.GetBeanTest">
<property name="contactService" ref="contactService"/>
</bean>
当我运行 worflow 时,我收到一个错误:
06090000 包装异常(带有状态模板):委托表达式 ${taskBean} 没有解析为接口 org.activiti.engine.impl.pvm.delegate.ActivityBehavior 或接口 org.activiti.engine.delegate.JavaDelegate 的实现
任何/所有回复表示赞赏!提前致谢。