java 服务任务 有三种实现方式
1. activiti:class 要实现 javaDelegate或ActivityBehavior
2. activiti:delegateExpression 也要实现上面两个类
3. activiti:expression 直接调用javaBean
第一种方式在前面博客中已经实现过了,这里实现一下2和3这两个方式
activiti:delegateExpression的实现方式:
1. bmpn中的serviceTask中引用类
<process id="leaveBill" name="leaveBillprocess" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="usertask1" name="User Task"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<serviceTask id="servicetask1" name="Service Task"></serviceTask>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="servicetask1" activiti:delegateExpression="${myDelegate}"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
</process>
2. 定义myDelegate
public class Mydelegate implements JavaDelegate,Serializable{
@Override
public void execute(DelegateExecution execution) {
System.out.println("自定义java类");
}
}
RuntimeService runtimeService = engine.getRuntimeService();
Deployment de = rs.createDeployment().addClasspathResource("test.bpmn").deploy();
ProcessDefinition defi = rs.createProcessDefinitionQuery().deploymentId(de.getId()).singleResult();
Map<String,Object> vars=new HashMap<>();
vars.put("myDelegate", new Mydelegate());
ProcessInstance pi = runtimeService.startProcessInstanceByKey(de.getKey(),vars);
实现activiti:expression 直接调用javaBean
1. 定义bmpn文件
<serviceTask id="servicetask2" name="Service Task"activiti:expression="${myBean.print(execution)}" ></serviceTask>
<sequenceFlow id="flow3" sourceRef="servicetask1" targetRef="servicetask2"
activiti:expression="${execution.setVariable('myName',myBean.name)}"></sequenceFlow>
2. 定义自定义类
public class MyBean implements Serializable{
private static final long serialVersionUID = 4888650505758480822L;
private String name="test";
public String getName() {
return name;
}
public void print(Execution exe) {
System.out.println("执行流id"+exe.getId());
}
}
RuntimeService runtimeService = engine.getRuntimeService();
Deployment de = rs.createDeployment().addClasspathResource("test.bpmn").deploy();
ProcessDefinition defi = rs.createProcessDefinitionQuery().deploymentId(de.getId()).singleResult();
Map<String,Object> vars=new HashMap<>();
vars.put("myBean", new Mydelegate());
ProcessInstance pi = runtimeService.startProcessInstanceByKey(de.getKey(),vars);
runtimeService.getVariable(pi.getId(), "myName");
activiti java service task 服务任务
最新推荐文章于 2024-07-15 09:51:46 发布