activiti java service task 服务任务

java 服务任务 有三种实现方式

1. activiti:class 要实现 javaDelegate或ActivityBehavior
2. activiti:delegateExpression 也要实现上面两个类
3. activiti:expression 直接调用javaBean

第一种方式在前面博客中已经实现过了,这里实现一下2和3这两个方式

activiti:delegateExpression的实现方式:

1. bmpn中的serviceTask中引用类

    
    
    
    
    
    
    



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 vars=new HashMap<>();
vars.put("myDelegate", new Mydelegate());
ProcessInstance pi = runtimeService.startProcessInstanceByKey(de.getKey(),vars);


实现activiti:expression 直接调用javaBean
1. 定义bmpn文件
 
    

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 vars=new HashMap<>();
vars.put("myBean", new Mydelegate());
ProcessInstance pi = runtimeService.startProcessInstanceByKey(de.getKey(),vars);
runtimeService.getVariable(pi.getId(), "myName");

activiti java service task 服务任务_第1张图片

你可能感兴趣的:(java,activiti)