工作流activiti5 使用流程变量
1、activiti配置文件activiti.cfg.xml
activiti.cfg.xml文件放在项目resources目录下,resources目录是activiti查找配置文件的默认目录
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="databaseSchemaUpdate" value="true" />
<property name="databaseType" value="mysql"/>
<property name="dataSource" ref="dataSource"/>
<property name="asyncExecutorActivate" value="false" />
<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/bpmn?autoReconnect=true&useUnicode=true&characterEncoding=UTF8" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="root" />
<property name="password" value="root" />
<property name="defaultAutoCommit" value="false"/>
</bean>
</beans>
2、流程图
<userTask activiti:assignee="#{userId}" activiti:exclusive="true" completionQuantity="1" id="_3" implementation="##unspecified" isForCompensation="false" name="approval task" startQuantity="1">
</userTask>
<userTask activiti:assignee="#{checkId}" activiti:exclusive="true" completionQuantity="1" id="_4" implementation="##unspecified" isForCompensation="false" name="check outcome" startQuantity="1">
</userTask>
使用#{userId}和#{checkId}设置流程变量
3、部署流程并启动流程实例
@Test
public void firstBpmn(){
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//部署流程
RepositoryService repositoryService = processEngine.getRepositoryService();
repositoryService.createDeployment()
.addClasspathResource("third.bpmn")
.deploy();
//启动流程实例并设置流程变量
Map<String,Object> variables = new HashMap<String,Object>();
variables.put("userId","张三峰");
variables.put("checkId","英语");
ProcessInstance processInstance = processEngine.getRuntimeService()
.startProcessInstanceByKey("PROCESS_2",variables);
System.out.println("id:"+processInstance.getId());
}
4、查看个人任务
@Test
public void task(){
// ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml")
// .buildProcessEngine();
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
List<Task> zhangsan = processEngine.getTaskService().createTaskQuery().taskAssignee("张三峰").list();
for (Task task:zhangsan){
System.out.println(task.getId()+" ---- "+task.getName());
}
}