Spring cloud和流程引擎activiti5整合代码
本章内容注册中心所需要代码可以参考https://blog.****.net/risheng****/article/details/89956473
本章得应用有两个:
1.eureka 注册中心,端口:1112
2.activiTest ,流程引擎,端口:8089
代码下载地址:https://download.****.net/download/risheng****/11195855
流程引擎代码如下:
pom.xml内容:
==================================================
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ecctest</groupId>
<artifactId>activiTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>activiTest</name>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.176</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.3.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.3.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>1.11.125</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-autoscaling</artifactId>
<version>1.11.125</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ec2</artifactId>
<version>1.11.125</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-route53</artifactId>
<version>1.11.125</version>
</dependency>
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>1.5.12</version>
</dependency>
<dependency>
<groupId>com.netflix.archaius</groupId>
<artifactId>archaius-core</artifactId>
<version>0.7.4</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>4.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.21.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.21.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
==================================================
application.properties内容:
#spring-cloud
spring.application.name=avtiviTest
server.port=8089
feign.hystrix.enabled=true
eureka.instance.preferIpAddress=true
eureka.client.serviceUrl.defaultZone=http://localhost:1112/eureka
ribbon.eureka.enabled=true
==================================================
applicationContext-activiti.xml内容:
<?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:aop="http://www.springframework.org/schema/aop" 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/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"
default-lazy-init="true">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />
</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="managementService" factory-bean="processEngine" factory-method="getManagementService" />
<bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
</beans>
==================================================
vacationRequest.bpmn20.xml流程定义文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
<process id="vacationRequest" name="请假申请流程" isExecutable="true">
<startEvent id="request" activiti:initiator="employeeName">
<extensionElements>
<activiti:formProperty id="numberOfDays" name="Number of days" type="long" variable="1" required="true"></activiti:formProperty>
<activiti:formProperty id="startDate" name="First day of holiday (dd-MM-yyy)" type="date" datePattern="dd-MM-yyyy hh:mm" required="true"></activiti:formProperty>
<activiti:formProperty id="vacationMotivation" name="Motivation" type="string"></activiti:formProperty>
</extensionElements>
</startEvent>
<userTask id="handleRequest" name="经理处理请假申请" activiti:candidateUsers="management">
<documentation>${employeeName} would like to take ${numberOfDays} day(s) of vacation (Motivation: ${vacationMotivation}).</documentation>
<extensionElements>
<activiti:formProperty id="vacationApproved" name="Do you approve this vacation" type="enum" required="true">
<activiti:value id="true" name="Approve"></activiti:value>
<activiti:value id="false" name="Reject"></activiti:value>
</activiti:formProperty>
<activiti:formProperty id="managerMotivation" name="Motivation" type="string"></activiti:formProperty>
</extensionElements>
</userTask>
<endEvent id="theEnd1"></endEvent>
<exclusiveGateway id="requestApprovedDecision" name="是否同意?"></exclusiveGateway>
<serviceTask id="sendApprovalMail" name="发送电子邮件" activiti:delegateExpression="${busiServiceTaskImpl}"></serviceTask>
<userTask id="adjustVacationRequestTask" name="调整重新申请" activiti:candidateUsers="${employeeName}">
<documentation>Your manager has disapproved your vacation request for ${numberOfDays} days.
Reason: ${managerMotivation}</documentation>
<extensionElements>
<activiti:formProperty id="numberOfDays" name="Number of days" type="long" variable="${numberOfDays}" required="true"></activiti:formProperty>
<activiti:formProperty id="startDate" name="First day of holiday (dd-MM-yyy)" type="date" datePattern="dd-MM-yyyy hh:mm" required="true"></activiti:formProperty>
<activiti:formProperty id="vacationMotivation" name="Motivation" type="string" variable="${vacationMotivation}"></activiti:formProperty>
<activiti:formProperty id="resendRequest" name="Resend vacation request to manager?" type="enum" required="true">
<activiti:value id="true" name="Yes"></activiti:value>
<activiti:value id="false" name="No"></activiti:value>
</activiti:formProperty>
</extensionElements>
</userTask>
<endEvent id="theEnd2"></endEvent>
<exclusiveGateway id="resendRequestDecision" name="是否重新申请?"></exclusiveGateway>
<sequenceFlow id="flow2" sourceRef="handleRequest" targetRef="requestApprovedDecision"></sequenceFlow>
<sequenceFlow id="flow4" sourceRef="sendApprovalMail" targetRef="theEnd1"></sequenceFlow>
<sequenceFlow id="flow3" sourceRef="requestApprovedDecision" targetRef="sendApprovalMail">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${vacationApproved == 'true'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow5" sourceRef="requestApprovedDecision" targetRef="adjustVacationRequestTask">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${vacationApproved == 'false'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow7" sourceRef="resendRequestDecision" targetRef="handleRequest">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${resendRequest == 'true'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow8" sourceRef="resendRequestDecision" targetRef="theEnd2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${resendRequest == 'false'}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow6" sourceRef="adjustVacationRequestTask" targetRef="resendRequestDecision"></sequenceFlow>
<sequenceFlow id="flow1" sourceRef="request" targetRef="handleRequest"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_vacationRequest">
<bpmndi:BPMNPlane bpmnElement="vacationRequest" id="BPMNPlane_vacationRequest">
<bpmndi:BPMNShape bpmnElement="request" id="BPMNShape_request">
<omgdc:Bounds height="30.0" width="30.0" x="90.0" y="100.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="handleRequest" id="BPMNShape_handleRequest">
<omgdc:Bounds height="80.0" width="100.0" x="225.0" y="75.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="theEnd1" id="BPMNShape_theEnd1">
<omgdc:Bounds height="28.0" width="28.0" x="795.0" y="101.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="requestApprovedDecision" id="BPMNShape_requestApprovedDecision">
<omgdc:Bounds height="40.0" width="40.0" x="435.0" y="95.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sendApprovalMail" id="BPMNShape_sendApprovalMail">
<omgdc:Bounds height="80.0" width="100.0" x="570.0" y="75.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="adjustVacationRequestTask" id="BPMNShape_adjustVacationRequestTask">
<omgdc:Bounds height="80.0" width="100.0" x="405.0" y="220.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="theEnd2" id="BPMNShape_theEnd2">
<omgdc:Bounds height="28.0" width="28.0" x="261.0" y="330.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="resendRequestDecision" id="BPMNShape_resendRequestDecision">
<omgdc:Bounds height="40.0" width="40.0" x="255.0" y="240.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="120.0" y="115.0"></omgdi:waypoint>
<omgdi:waypoint x="225.0" y="115.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="325.0" y="115.0"></omgdi:waypoint>
<omgdi:waypoint x="435.0" y="115.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="475.0" y="115.0"></omgdi:waypoint>
<omgdi:waypoint x="570.0" y="115.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
<omgdi:waypoint x="670.0" y="115.0"></omgdi:waypoint>
<omgdi:waypoint x="795.0" y="115.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="455.0" y="135.0"></omgdi:waypoint>
<omgdi:waypoint x="455.0" y="220.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="405.0" y="260.0"></omgdi:waypoint>
<omgdi:waypoint x="295.0" y="260.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="275.0" y="240.0"></omgdi:waypoint>
<omgdi:waypoint x="275.0" y="155.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="275.0" y="280.0"></omgdi:waypoint>
<omgdi:waypoint x="275.0" y="330.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
==================================================
启动类:
package com.ecctest.activi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
@ComponentScan(basePackages = "com.ecctest.activi")
@EnableDiscoveryClient
@SpringBootApplication
//@ImportResource({"classpath*:/spring/applicationContext-*.xml"})
@ImportResource({"classpath:/applicationContext-activiti.xml"})
public class ActiviApplication {
public static void main(String[] args) {
SpringApplication.run(ActiviApplication.class, args);
}
}
==================================================
Ctrl类:
package com.ecctest.activi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* 无需登录验证的功能控制器
*/
@RestController
public class ActiviController {
@Autowired
private ActiviService activiService;
@RequestMapping(value = "/test/testFlow1", method = RequestMethod.GET)
public String testFlow1() throws Exception {
String bb1="ketmit";
String bb2="I'm really tired!";
String retMsg=activiService.doTest1(bb1,bb2);
//map.put("retMsg", retMsg);
//String retMsg="OK";
return retMsg;
}
@RequestMapping(value = "/test/testFlow2", method = RequestMethod.GET)
public String testFlow2() throws Exception {
String bb1="ketmit";
String bb2="I'm really tired!";
String retMsg=activiService.doTest2(bb1,bb2);
//String retMsg="OK";
return retMsg;
}
}
==================================================
activiti业务类:
package com.ecctest.activi;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ActiviService {
@Autowired
private RepositoryService repositoryService ;
@Autowired
private RuntimeService runtimeService ;
@Autowired
private TaskService taskService ;
public String doTest1(String bb1,String bb2) throws Exception{
//ProcessEngine processEngine=processEngineObj.getObject();
//RepositoryService repositoryService = processEngine.getRepositoryService();
// ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// RepositoryService repositoryService = processEngine.getRepositoryService();
// repositoryService.createDeployment()
// .addClasspathResource("org/activiti/test/testBMPN.xml")
// .deploy();
String filePath = "D:/workSpace/activiTest/src/main/resources/org/activiti/test/vacationRequest.bpmn20.xml";
FileInputStream fis = new FileInputStream(filePath);
repositoryService.createDeployment().addInputStream("userAndGroupInUserTask.bpmn", fis).deploy();// 用userAndGroupInUserTask.bpmn作为资源名称
System.out
.println("Number of process definitions: " + repositoryService.createProcessDefinitionQuery().count());
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employeeName", "Kermit");
variables.put("numberOfDays", new Integer(4));
variables.put("vacationMotivation", "I'm really tired!");
//RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("vacationRequest", variables);
// Verify that we started a new process instance
System.out.println("Number of process instances: " + runtimeService.createProcessInstanceQuery().count());
//TaskService taskService = processEngine.getTaskService();
//List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
List<Task> tasks = taskService.createTaskQuery().taskCandidateUser("management").list();
for (Task task : tasks) {
System.out.println("Task available: " + task.getName());
}
Task task = tasks.get(0);
Map<String, Object> taskVariables = new HashMap<String, Object>();
taskVariables.put("vacationApproved", "false");
taskVariables.put("managerMotivation", "We have a tight deadline!");
taskService.complete(task.getId(), taskVariables);
//职员Kermit重新申请
tasks = taskService.createTaskQuery().taskCandidateUser("Kermit").list();
task = tasks.get(0);
System.out.println("Task available: " + task.getName());
taskVariables = new HashMap<String, Object>();
taskVariables.put("employeeName", "Kermit");
taskVariables.put("numberOfDays", new Integer(4));
taskVariables.put("vacationMotivation", "I'm really tired!");
taskVariables.put("resendRequest", "false");
taskService.complete(task.getId(), taskVariables);
//流程结束
return "流程1结束";
}
public String doTest2(String bb1,String bb2) throws Exception{
// ProcessEngine processEngine=processEngineObj.getObject();
//
// ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// RepositoryService repositoryService = processEngine.getRepositoryService();
// repositoryService.createDeployment()
// .addClasspathResource("org/activiti/test/testBMPN.xml")
// .deploy();
String filePath = "D:/workSpace/activiTest/src/main/resources/org/activiti/test/vacationRequest.bpmn20.xml";
FileInputStream fis = new FileInputStream(filePath);
repositoryService.createDeployment().addInputStream("userAndGroupInUserTask.bpmn", fis).deploy();// 用userAndGroupInUserTask.bpmn作为资源名称
System.out
.println("Number of process definitions: " + repositoryService.createProcessDefinitionQuery().count());
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("employeeName", "Kermit");
variables.put("numberOfDays", new Integer(4));
variables.put("vacationMotivation", "I'm really tired!");
//variables.put("busiServiceTaskImpl", new BusiServiceTaskImpl()); //spring cloud无需创建对象。会自动注入
//RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("vacationRequest", variables);
// Verify that we started a new process instance
System.out.println("Number of process instances: " + runtimeService.createProcessInstanceQuery().count());
//TaskService taskService = processEngine.getTaskService();
//List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
List<Task> tasks = taskService.createTaskQuery().taskCandidateUser("management").list();
for (Task task : tasks) {
System.out.println("Task available: " + task.getName());
}
Task task = tasks.get(0);
Map<String, Object> taskVariables = new HashMap<String, Object>();
taskVariables.put("vacationApproved", "true");
taskVariables.put("managerMotivation", "I agree!");
taskService.complete(task.getId(), taskVariables);
//职员Kermit重新申请
tasks = taskService.createTaskQuery().taskCandidateUser("Kermit").list();
//流程结束
return "流程2结束";
}
}
==================================================
电子邮件服务类:
package com.ecctest.activi;
import java.io.Serializable;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
* 服务节点执行的任务
*/
@Service(value="busiServiceTaskImpl")
public class BusiServiceTaskImpl implements Serializable,JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
System.out.println("variavles=" + execution.getVariables());
System.out.println("send Mail ============经理同意申请了!");
//sendMail();
}
}
==================================================
具体得流程图看这里:
================================================================
两个应用,启动完毕后,访问业务地址1:
http://localhost:8089/test/testFlow1
页面显示结果:
流程1结束
后台日志输出:
Number of process definitions: 5
Number of process instances: 1
Task available: 经理处理请假申请
Task available: 调整重新申请
访问业务地址2:
http://localhost:8089/test/testFlow2
页面显示结果:
流程2结束
后台日志输出:
Number of process definitions: 6
Number of process instances: 1
Task available: 经理处理请假申请
variavles={employeeName=Kermit, vacationMotivation=I'm really tired!, vacationApproved=true, managerMotivation=I agree!, numberOfDays=4}
send Mail ============经理同意申请了!
=================================================
流程1和流程2走向不一样。从业务流程图能看出有两个结束点,所以展示了两段代码来实现业务流程。
==================================================
另外是Activiti 5的参考资料:中文版:http://www.mossle.com/docs/activiti/index.html#activitiDesigner
英文版:https://www.activiti.org/5.x/userguide
Activiti 5的流程引擎图形编辑工具下载地址:https://github.com/Activiti/Activiti/releases/download/activiti-5.22.0/activiti-5.22.0.zip
下载后解压部署到Tomcat8的webapps下就可以。
访问地址:http://localhost:8080/activiti-explorer/
用户名和密码:
kermit
kermit
==================================================
图形化编辑工具并非必须的,似乎还有跟IDE集成的插件方案可以编辑BPMN的流程文件。中文文档上的例子并不正确,作者已经修改成正确的流程定义,可以通过流程引擎图形编辑工具导入,编辑完成后导出。然后部署到项目里面运行。
项目代码里面有两个MainStart.java和MainStart2.java如何不通过Spring引擎来调用activi,注意两种调用方式的区别。