SpringBoot集成Activiti6教程

SpringBoot集成Activiti6教程第一步在项目pom.xml文件中添加所需依赖<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="htt

大家好,又见面了,我是你们的朋友全栈君。

第一步在项目pom.xml文件中添加所需依赖

<?xml version="1.0" encoding="UTF-8"?>
<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.springboot.demo</groupId>
	<artifactId>springboot-activiti-demo</artifactId>
	<version>1.0.0</version>
	<packaging>war</packaging>

	<name>springboot-activiti-demo</name>
	<description>springboot-demo</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.9.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-web</artifactId>  
        </dependency>  
        <dependency>  
            <groupId>org.activiti</groupId>  
            <artifactId>activiti-spring-boot-starter-basic</artifactId>  
            <version>6.0.0</version>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-data-jpa</artifactId>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-thymeleaf</artifactId>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-web</artifactId>  
        </dependency>  
  
        <dependency>  
            <groupId>mysql</groupId>  
            <artifactId>mysql-connector-java</artifactId>  
            <scope>runtime</scope>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-tomcat</artifactId>  
        </dependency>  
        <dependency>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-test</artifactId>  
            <scope>test</scope>  
        </dependency>  
    </dependencies> 

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			
			<plugin>
		        <groupId>org.apache.tomcat.maven</groupId>
		        <artifactId>tomcat7-maven-plugin</artifactId>
		        <configuration>
		          <port>8081</port>
		          <path>/activity</path>
		          <systemProperties>
		            <com.sun.management.jmxremote.port>4000</com.sun.management.jmxremote.port>
		          </systemProperties>
		        </configuration>
		     </plugin>
		</plugins>
	</build>


</project>

第二步:编写示例接口和接口实现类

接口类(ActivityConsumerService.java)

package com.springboot.demo.service;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController  
@RequestMapping("/test")  
public interface ActivityConsumerService {  
    /** 
     * 流程demo 
     * @return 
     */  
    @RequestMapping(value="/activitiDemo",method=RequestMethod.GET)  
    public boolean startActivityDemo();  
      
}  

接口实现类(ActivityConsumerServiceImpl.java)

package com.springboot.demo.service.impl;

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.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springboot.demo.service.ActivityConsumerService;

@Service("activityService")  
public class ActivityConsumerServiceImpl implements ActivityConsumerService {  
  
    @Autowired  
    private RuntimeService runtimeService;  
    @Autowired  
    private TaskService taskService;  
    
    @Autowired
    private RepositoryService repositoryService;
      
    @Override  
    public boolean startActivityDemo() {  
        System.out.println("method startActivityDemo begin....");  
        
        System.out.println( "调用流程存储服务,查询部署数量:"
                + repositoryService.createDeploymentQuery().count());
        

      
        Map<String,Object> map = new HashMap<String,Object>();  
        map.put("apply","zhangsan");  
        map.put("approve","lisi");  
        
        //流程启动  
        ExecutionEntity pi1 = (ExecutionEntity) runtimeService.startProcessInstanceByKey("leave",map);  
       
        List<Task> tq=taskService.createTaskQuery().taskAssignee("zhangsan").list();
        System.out.println(tq.size());
        String assignee = "zhangsan";//当前任务办理人  
        List<Task> tasks = taskService//与任务相关的Service  
                .createTaskQuery()//创建一个任务查询对象  
                .taskAssignee(assignee)  
                .list();  
        if(tasks !=null && tasks.size()>0){  
            for(Task task:tasks){  
                System.out.println("任务ID:"+task.getId());  
                System.out.println("任务的办理人:"+task.getAssignee());  
                System.out.println("任务名称:"+task.getName());  
                System.out.println("任务的创建时间:"+task.getCreateTime());  

                System.out.println("流程实例ID:"+task.getProcessInstanceId());
                System.out.println("#####################################");  
            }  
        }  
     
        System.out.println("method startActivityDemo end....");  
        return false;  
    }  
}  

第三步:在src/main/java/resources目录下新建processes目录,并在该目录下新增一个业务流程文件

MyProcess.bpmn:

<?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" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="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/testm1510735932336" id="m1510735932336" name="">
  <process id="leave" isExecutable="true" isClosed="false" processType="None">
    <startEvent id="_2" name="StartEvent"></startEvent>
    <endEvent id="_3" name="EndEvent"></endEvent>
    <userTask id="approve" name="经理审批" activiti:assignee="${approve}"></userTask>
    <exclusiveGateway id="_5" name="ExclusiveGateway"></exclusiveGateway>
    <sequenceFlow id="_6" sourceRef="approve" targetRef="_5"></sequenceFlow>
    <sequenceFlow id="_7" name="通过" sourceRef="_5" targetRef="_3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="application" name="提交申请" activiti:assignee="${apply}"></userTask>
    <sequenceFlow id="_9" sourceRef="_2" targetRef="application"></sequenceFlow>
    <sequenceFlow id="_10" sourceRef="application" targetRef="approve"></sequenceFlow>
    <userTask id="modify" name="修改申请" activiti:assignee="${apply}"></userTask>
    <sequenceFlow id="_12" name="不通过" sourceRef="_5" targetRef="modify">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_13" sourceRef="modify" targetRef="approve"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_leave">
    <bpmndi:BPMNPlane bpmnElement="leave" id="BPMNPlane_leave">
      <bpmndi:BPMNShape bpmnElement="_2" id="BPMNShape__2">
        <omgdc:Bounds height="35.0" width="35.0" x="15.0" y="60.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="BPMNShape__3">
        <omgdc:Bounds height="35.0" width="35.0" x="630.0" y="63.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="approve" id="BPMNShape_approve">
        <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="50.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="BPMNShape__5">
        <omgdc:Bounds height="40.0" width="40.0" x="505.0" y="60.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="application" id="BPMNShape_application">
        <omgdc:Bounds height="55.0" width="85.0" x="135.0" y="50.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="modify" id="BPMNShape_modify">
        <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6">
        <omgdi:waypoint x="400.0" y="77.0"></omgdi:waypoint>
        <omgdi:waypoint x="505.0" y="80.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7">
        <omgdi:waypoint x="545.0" y="80.0"></omgdi:waypoint>
        <omgdi:waypoint x="630.0" y="80.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9">
        <omgdi:waypoint x="50.0" y="77.0"></omgdi:waypoint>
        <omgdi:waypoint x="135.0" y="77.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10">
        <omgdi:waypoint x="220.0" y="77.0"></omgdi:waypoint>
        <omgdi:waypoint x="315.0" y="77.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12">
        <omgdi:waypoint x="525.0" y="100.0"></omgdi:waypoint>
        <omgdi:waypoint x="525.0" y="177.0"></omgdi:waypoint>
        <omgdi:waypoint x="400.0" y="177.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13">
        <omgdi:waypoint x="357.0" y="150.0"></omgdi:waypoint>
        <omgdi:waypoint x="357.0" y="105.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

项目目录结构如下图:

SpringBoot集成Activiti6教程

 

第四步:在mysql数据库服务器增加数据库:activiti-demo

第五步:设置application.properties配置自己应用的相关信息

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/activiti-demo?characterEncoding=utf8&useSSL=true
spring.datasource.username=root
spring.datasource.password=ROOT
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.show-sql=true
server.port=8081
server.context-path=/
server.session.timeout=10
server.tomcat.uri-encoding=UTF-8

第六步:启动应用后,在浏览器地址栏输入访问地址:

http://localhost:8081/test/activitiDemo

第七步:看控制后台输出结果如下图,即代表成功。

SpringBoot集成Activiti6教程

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/162631.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • Ubuntu Mobile Demo at IDF Shanghai (英文)

    Ubuntu Mobile Demo at IDF Shanghai (英文)

  • windows通过命令行查看进程杀死进程_windows强制结束进程命令

    windows通过命令行查看进程杀死进程_windows强制结束进程命令tasklist#查看进程信息,tasklist命令的筛选器功能非常强大先使用tasklist命令查看当前系统中的进程列表,然后针对你要杀的进程使用taskkill命令如要杀nginx.exe进程,命令如下:taskkill/imnginx.exe/f也可以使用pid杀:taskkill/pid{pid}您可以运行taskkill/?来获取更多更多有关taskkill的信息。…

  • 分秒必争域的时间同步问题[为企业部署Windows Server 2008系列十四]

    分秒必争域的时间同步问题[为企业部署Windows Server 2008系列十四]

  • FTP客户端FlashFXP激活成功教程教程[通俗易懂]

    FTP客户端FlashFXP激活成功教程教程[通俗易懂]flashfxp5.4下载地址:https://www.flashfxp.com/download激活成功教程工具下载地址:链接:https://pan.baidu.com/s/17Dq_OnH-ua9fbOuvMIdRXQ密码:laat下载之后然后正常安装就行了,安装完毕之后,先别打开软件,激活成功教程工具下载之后,包含两个文件,解压到flashfxp的安装位置根目录,如下:双击打开Fl…

  • php源码审计_代码审计入门cms

    php源码审计_代码审计入门cms目录一:代码审计的定义二:为什么选择PHP学习代码审计三:入门准备四:PHP常见的套路4.1 代码结构4.2 目录结构4.3参考项目五:如何调试代码六:代码审计的本质一:代码审计的定义通过阅读一些程序的源码去发现潜在的漏洞,比如代码不规范,算法性能不够,代码重用性不强以及其他的缺陷等等从安全人员的角度来看是:查找代码中是否存在安全问题,推断用户在操…

  • PID控制器开发笔记之十二:模糊PID控制器的实现[通俗易懂]

    PID控制器开发笔记之十二:模糊PID控制器的实现[通俗易懂]在现实控制中,被控系统并非是线性时不变的,往往需要动态调整PID的参数,而模糊控制正好能够满足这一需求,所以在接下来的这一节我们将讨论模糊PID控制器的相关问题。模糊PID控制器是将模糊算法与PID控制参数的自整定相结合的一种控制算法。可以说是模糊算法在PID参数整定上的应用。1、模糊算法的原理模糊算法是一种基于智能推理的算法,虽然称之为模糊算法其实并不模糊,实际上是一种逐步求精的思想。一…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号