我正在尝试通过Spring托管流程引擎使用Activiti 5.5来使工作流正常工作,但遇到了一些麻烦。
我的工作流程中有一个ServiceTask,可以解析为Spring Managed Bean。看起来像这样:
<serviceTask id="springTask1" name="BeanTest" activiti:delegateExpression="${taskBean}"></serviceTask>
我不是通过代码启动过程,而是通过activti-rest api或表单启动过程。我如何从Bean内部获取执行此任务的上下文,以便我可以添加可以在以后的任务(例如电子邮件)中引用的过程变量。我尝试查看Activiti 5.5附带的春季示例,但看不到我的示例与示例有何不同。我正在实现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的实现] >
任何/所有答复表示赞赏!预先感谢。
我正在尝试通过Spring托管流程引擎使用Activiti 5.5来使工作流正常工作,但遇到了一些麻烦。我的工作流程中有一个ServiceTask,可以解析为Spring Managed Bean...。
您也可以通过这种方式在服务任务中使用spring bean: