springboot activiti工作流简单示例
最近一直研究springboot,根据工作需求,工作流需要作为一个单独的微服务工程来提供给其他服务调用,现在简单的写下工作流(使用的activiti)微服务的搭建与简单使用
jdk:1.8
数据库:mysql 5.7
IDE:eclipse
springboot:1.5.8
activiti:6.0.0
1.新建空白的maven微服务架构
-
<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.xxx</groupId>
-
<artifactId>xxx</artifactId>
-
<version>0.0.1-SNAPSHOT</version>
-
<properties>
-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-
<java.version>1.8</java.version>
-
</properties>
-
-
<parent>
-
<groupId>org.springframework.boot</groupId>
-
<artifactId>spring-boot-starter-parent</artifactId>
-
<version>1.5.8.RELEASE</version>
-
</parent>
-
<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>
-
</plugins>
-
</build>
-
</project>
确认服务是可用
2.连接服务名、服务端口、数据库配置
-
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/activity?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=/activity
-
server.session.timeout=10
-
server.tomcat.uri-encoding=UTF-8
确认配置的数据库可用
3.main
-
import org.springframework.boot.SpringApplication;
-
import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-
/**
-
* Created by Guo on 2017/11/15.
-
*/
-
@SpringBootApplication
-
public class ActivityApp
-
{
-
public static void main(String[] args)
-
{
-
SpringApplication.run(ActivityApp.class, args);
-
}
-
}
4.service及实现
-
import org.activiti.engine.task.TaskQuery;
-
import org.springframework.web.bind.annotation.RequestMapping;
-
import org.springframework.web.bind.annotation.RequestMethod;
-
import org.springframework.web.bind.annotation.RestController;
-
-
@RestController
-
@RequestMapping("/activityService")
-
public interface ActivityConsumerService {
-
/**
-
* 流程demo
-
* @return
-
*/
-
@RequestMapping(value="/startActivityDemo",method=RequestMethod.GET)
-
public boolean startActivityDemo();
-
-
}
impl
-
import java.util.HashMap;
-
import java.util.Map;
-
-
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.apache.commons.lang3.StringUtils;
-
import org.springframework.beans.factory.annotation.Autowired;
-
import org.springframework.stereotype.Service;
-
-
import com.hongguaninfo.activity.service.ActivityConsumerService;
-
@Service("activityService")
-
public class ActivityConsumerServiceImpl implements ActivityConsumerService {
-
-
@Autowired
-
private RuntimeService runtimeService;
-
@Autowired
-
private TaskService taskService;
-
-
@Override
-
public boolean startActivityDemo() {
-
System.out.println("method startActivityDemo begin....");
-
Map<String,Object> map = new HashMap<String,Object>();
-
map.put("apply","zhangsan");
-
map.put("approve","lisi");
-
//流程启动
-
ExecutionEntity pi1 = (ExecutionEntity) runtimeService.startProcessInstanceByKey("leave",map);
-
String processId = pi1.getId();
-
String taskId = pi1.getTasks().get(0).getId();
-
taskService.complete(taskId, map);//完成第一步申请
-
-
Task task = taskService.createTaskQuery().processInstanceId(processId).singleResult();
-
String taskId2 = task.getId();
-
map.put("pass", false);
-
taskService.complete(taskId2, map);//驳回申请
-
System.out.println("method startActivityDemo end....");
-
return false;
-
}
-
}
5.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>
需要认知的问题:.项目启动的时候,activiti会自动在mysql中创建activiti相关表,不用像oracle那样需要手动去创建
6.验证
用浏览器访问地址:http://127.0.0.1:8081/activity/activityService/startActivityDemo
打印了预计的日志,没有报错信息,查看数据库中的act_ru_task表,发现刚才执行形成的数据,项目成功。
-
spring:
-
activiti:
-
####校验流程文件,默认校验resources下的processes文件夹里的流程文件
-
check-process-definitions: false
即启动项目,不去校验processes。
原文地址:https://blog.csdn.net/kkkder/article/details/78562349
springboot activiti工作流简单示例的更多相关文章
- Activiti工作流简单入门 (zhuan)
https://my.oschina.NET/Barudisshu/blog/309721 *********************************************** 摘要: 自j ...
- SpringBoot整合websocket简单示例
依赖 <!-- springboot整合websocket --> <dependency> <groupId>org.springframework.boot&l ...
- RabbitMQ基础组件和SpringBoot整合RabbitMQ简单示例
交换器(Exchange) 交换器就像路由器,我们先是把消息发到交换器,然后交换器再根据绑定键(binding key)和生产者发送消息时的路由键routingKey, 按照交换类型Exchange ...
- springboot activiti 工作流版本 集成代码生成器 shiro 安全框架
官网:www.fhadmin.org 工作流模块---------------------------------------------------------------------------- ...
- springboot整合redis简单示例
一.项目架构 二.项目内容 1.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...
- Activiti工作流小序曲
一般涉及到OA.ERP等公司办公系统都必须有一套办公流程,这时候使用activiti工作流框架会大大减轻我们的工作量,提高我们的开发效率. Activiti工作流简单介绍: 工作流(workflow) ...
- Activiti工作流的应用示例 (官方guide项目方式)
转: Activiti工作流的应用示例 1.新建流程模型 模型管理->模型工作区 点击“创建”后会立即跳转到“流程在线设计器”页面,请参考下一节 2.在线流程设计器 模型管理->模型工作区 ...
- 2017.2.20 activiti实战--第二章--搭建Activiti开发环境及简单示例(二)简单示例
学习资料:<Activiti实战> 第一章 搭建Activiti开发环境及简单示例 2.5 简单流程图及其执行过程 (1)leave.bpmn 后缀名必须是bpmn.安装了activiti ...
- dubbo+zookeeper+springboot简单示例
目录 dubbo+zookeeper+springboot简单示例 zookeeper安装使用 api子模块 生产者producer 消费者consumer @(目录) dubbo+zookeeper ...
随机推荐
- AutoDesk产品,Maya 2018 安装,Microsoft Visual C++ 2012 安装失败,结果 = -2147024546,安装Microsoft Visual C++ 2012 Redistributable 错误0x80070005 等等
今日老弟装Maya 2018出现问题,我帮忙解决了一下问题,过程颇为曲折,记录一下,看能否帮到有类似困惑的朋友. 我和老弟的电脑牌子一样,就现在自己电脑上装了,竟然开始和他的错误是一样的!都是Micr ...
- 构建PaaS的开源平台:CloudFoundry
CloudFoundry的架构: 点评:这是vmware用ruby开发的一个paas,由于对ruby不太熟悉,还是比较难理解. refer to :http://www.oschina.net/que ...
- vue-cli3 搭建的前端项目基础模板
基于 vue-cli3 搭建的前端模板,fork 或 clone 本仓库,即可搭建完成一个新项目的基础模板,源码地址,欢迎 star 或 fork 特性 CSS 预编译语言:less Ajax: ax ...
- JS 鼠标键盘HTML事件
- java reference(转)
http://blog.163.com/xubin_3@126/blog/static/112987702200962211145825/ 在Java中的引用类型,是指除了基本的变量类型之外的所有类型 ...
- java jvm 参数 -Xms -Xmx -Xmn -Xss 调优总结
常见配置举例 堆大小设置 JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制;系统的可用虚拟内存限制;系统的可用物理内存限制.32位系统 下,一般限制在1.5 ...
- LeetCode97 Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. (Hard) For example,Giv ...
- ssh 出错 Permission denied (publickey,password).
将客户端的~/.ssh/know_hosts 文件删掉试试 ssh debug信息 ssh -vvv xxx@192.168.1.111
- day10-02_多线程之进程与线程的pid
一.多个线程之间PID的区别 主进程跟线程的pid是一样的 from threading import Thread from multiprocessing import Process impor ...
- Docker 学习笔记 2019-05-27
Docker 学习笔记 2019-05-27 可以很方便的打包应用. 使用 docker-compose 更方便. 每个发行版安装方式不一样,如果 centos 直接安装很可能会安装成旧版本. Lin ...