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 ...
随机推荐
- Python中的进程池与线程池(包含代码)
Python中的进程池与线程池 引入进程池与线程池 使用ProcessPoolExecutor进程池,使用ThreadPoolExecutor 使用shutdown 使用submit同步调用 使用su ...
- 为Apple Watch而战-----(初级篇)
重要 本文档是开发过程中使用的API或者技术的初步文档.苹果提供该文档以便于开发者使用苹果产品上使用技术和编程接口.后期该文档中信息会有所变动,所以依据本文档开发的软件应当使用最终的操作系统软件进行测 ...
- Webpack ERROR in Path must be a string. Received undefined
在学习webpack过程中,我遇到的下面这个问题及解决方法. 问题如下: node版本如下截图: package.json文件截图: webpack.config.js文件截图: 然后,我运行项目,报 ...
- 【祈福】NOIP战后占卜:众星陨落,天命难违
Day1 加上看题,做完第一题之后我已经只剩两个小时半了. 然后凭着一定要做完第一题和第二题的坚定信念. 我耗到了只剩一个小时半,结果正解还是没想出来. 其实我从只剩两小时的时候,就有了打第二题的暴力 ...
- 初识Django(DNS原理及web框架)
DNS的原理 假设www.abc.com的主机要查询www.xyz.abc.com的服务器ip地址. 知识点 1.hosts文件:以静态映射的方式提供IP地址与主机名的对照表,类似ARP表 2.域:a ...
- bzoj2424 订货
Description 某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月初的库存量为零,第n月月底的库存量也为 ...
- closest和parents方法区别
今天第一次看到closest方法,以前也从来没用过. 该方法从元素本身开始往上查找,返回最近的匹配的祖先元素. 1.closest查找开始于自身,parents开始于元素父级 2.closest向上查 ...
- 简单线性回归(梯度下降法) python实现
grad_desc .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { bord ...
- hdu5131 贪心
#include<stdio.h> #include<string.h> #include<algorithm> #include<string> #i ...
- 2019-7-25-VisualStudio-2019-新创建项目添加-git-仓库
title author date CreateTime categories VisualStudio 2019 新创建项目添加 git 仓库 lindexi 2019-7-25 15:8:15 + ...