一、目录展示
二、导入依赖
<properties> <project.build.sourceEncoding>UTF-8project.build.sourceEncoding> <maven.compiler.source>1.7maven.compiler.source> <maven.compiler.target>1.7maven.compiler.target> <slf4j.version>1.6.6slf4j.version> <log4j.version>1.2.12log4j.version> properties> <dependencies> <dependency> <groupId>org.activitigroupId> <artifactId>activiti-engineartifactId> <version>7.0.0.Beta1version> dependency> <dependency> <groupId>org.activitigroupId> <artifactId>activiti-bpmn-modelartifactId> <version>7.0.0.Beta1version> dependency> <dependency> <groupId>org.activitigroupId> <artifactId>activiti-bpmn-converterartifactId> <version>7.0.0.Beta1version> dependency> <dependency> <groupId>org.activitigroupId> <artifactId>activiti-json-converterartifactId> <version>7.0.0.Beta1version> dependency> <dependency> <groupId>org.activitigroupId> <artifactId>activiti-bpmn-layoutartifactId> <version>7.0.0.Beta1version> dependency> <dependency> <groupId>org.activiti.cloudgroupId> <artifactId>activiti-cloud-services-apiartifactId> <version>7.0.0.Beta1version> dependency> <dependency> <groupId>org.activitigroupId> <artifactId>activiti-springartifactId> <version>7.0.0.Beta1version> dependency> <dependency> <groupId>mysqlgroupId> <artifactId>mysql-connector-javaartifactId> <version>5.1.38version> dependency> <dependency> <groupId>junitgroupId> <artifactId>junitartifactId> <version>4.12version> dependency> <dependency> <groupId>org.springframeworkgroupId> <artifactId>spring-testartifactId> <version>5.0.7.RELEASEversion> dependency> <dependency> <groupId>log4jgroupId> <artifactId>log4jartifactId> <version>${log4j.version}version> dependency> <dependency> <groupId>org.slf4jgroupId> <artifactId>slf4j-apiartifactId> <version>${slf4j.version}version> dependency> <dependency> <groupId>org.slf4jgroupId> <artifactId>slf4j-log4j12artifactId> <version>${slf4j.version}version> dependency> <dependency> <groupId>org.mybatisgroupId> <artifactId>mybatisartifactId> <version>3.4.5version> dependency> <dependency> <groupId>commons-dbcpgroupId> <artifactId>commons-dbcpartifactId> <version>1.4version> dependency> <dependency> <groupId>commons-iogroupId> <artifactId>commons-ioartifactId> <version>2.4version> dependency> dependencies>
三、配置文件
xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/activiti"/> <property name="username" value="root"/> <property name="password" value="123"/> bean> <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <property name="dataSource" ref="dataSource"/> <property name="transactionManager" ref="transactionManager"/> <property name="databaseSchemaUpdate" value="true"/> bean> <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"> <property name="processEngineConfiguration" ref="processEngineConfiguration"/> bean> <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="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> bean> beans>
四、流程bpmn文件
五、流程部署
1、代码块
package com.zn; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.runtime.ProcessInstance; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:activiti-spring.xml") public class ActivitiSpringTest { @Resource private RepositoryService repositoryService; @Resource private RuntimeService runtimeService; /** * 流程部署 */ @Test public void deployment(){ repositoryService.createDeployment() .addClasspathResource("bpmnfiles/holidayInclusiveGateway.bpmn") .name("测试Spring流程部署") .deploy(); } }
2、数据库
六、启动流程实例
1、代码块
package com.zn; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.runtime.ProcessInstance; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:activiti-spring.xml") public class ActivitiSpringTest { @Resource private RepositoryService repositoryService; @Resource private RuntimeService runtimeService; /** * 流程实例 */ @Test public void getInstance(){ //设置流程变量 MapassMap = new HashMap<>(); assMap.put("userType", 1); //启动流程实例 ProcessInstance holidayGroup = runtimeService.startProcessInstanceByKey("holidayInc", assMap); System.out.println("流程实例:" + holidayGroup.getId()); } }
2、数据库
七、处理任务
1、代码块
package com.zn; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:activiti-spring.xml") public class ActivitiSpringTest { @Resource private RepositoryService repositoryService; @Resource private RuntimeService runtimeService; @Resource private TaskService taskService; /* *任务处理 */ @Test public void completeTask(){ //查询到自己的任务,然后通过任务ID进行提交 Task task = taskService.createTaskQuery().processDefinitionKey("holidayInc").taskAssignee("zhangsan").singleResult(); //任务处理 taskService.complete(task.getId()); } }
2、数据库
八、处理任务
1、代码块
package com.zn; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:activiti-spring.xml") public class ActivitiSpringTest { @Resource private RepositoryService repositoryService; @Resource private RuntimeService runtimeService; @Resource private TaskService taskService; /* *任务处理 */ @Test public void completeTask(){ //查询到自己的任务,然后通过任务ID进行提交 Task task = taskService.createTaskQuery().processDefinitionKey("holidayInc").taskAssignee("lisi").singleResult(); //任务处理 taskService.complete(task.getId()); } }
2、数据库
九、处理任务
1、代码块
package com.zn; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:activiti-spring.xml") public class ActivitiSpringTest { @Resource private RepositoryService repositoryService; @Resource private RuntimeService runtimeService; @Resource private TaskService taskService; /* *任务处理 */ @Test public void completeTask(){ //查询到自己的任务,然后通过任务ID进行提交 Task task = taskService.createTaskQuery().processDefinitionKey("holidayInc").taskAssignee("wangwu").singleResult(); //任务处理 taskService.complete(task.getId()); } }
2、数据库
十、处理任务
1、代码块
package com.zn; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:activiti-spring.xml") public class ActivitiSpringTest { @Resource private RepositoryService repositoryService; @Resource private RuntimeService runtimeService; @Resource private TaskService taskService; /* *任务处理 */ @Test public void completeTask(){ //查询到自己的任务,然后通过任务ID进行提交 Task task = taskService.createTaskQuery().processDefinitionKey("holidayInc").taskAssignee("sunqi").singleResult(); //任务处理 taskService.complete(task.getId()); } }
2、数据库
十一、查看历史任务
1、代码块
package com.zn; import org.activiti.engine.HistoryService; import org.activiti.engine.RepositoryService; import org.activiti.engine.RuntimeService; import org.activiti.engine.TaskService; import org.activiti.engine.history.HistoricActivityInstance; import org.activiti.engine.history.HistoricActivityInstanceQuery; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:activiti-spring.xml") public class ActivitiSpringTest { @Resource private RepositoryService repositoryService; @Resource private RuntimeService runtimeService; @Resource private TaskService taskService; @Resource private HistoryService historyService; /** * 查看历史任务 */ @Test public void getHistory(){ //获取历史任务 HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService.createHistoricActivityInstanceQuery(); //获取指定流程实例的任务 historicActivityInstanceQuery.processInstanceId("2501"); //获取任务列表 Listlist = historicActivityInstanceQuery.list(); for (HistoricActivityInstance ai : list) { System.out.println("任务节点ID:"+ai.getActivityId()); System.out.println("任务节点名称:"+ai.getActivityName()); System.out.println("流程实例ID信息:"+ai.getProcessDefinitionId()); System.out.println("流程实例ID信息:"+ai.getProcessInstanceId()); System.out.println("=============================="); } } }
2、控制台