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 ...
随机推荐
- Ajax系列之二:核心对象XMLHttpRquest
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zhanghongjie0302/article/details/31432939 ...
- [运维]ESXI系统的安装 标签: 虚拟机运维vmware服务器虚拟化 2017-05-05 09:24 496人阅读 评论(15)
上篇博客说到了VMware vSphere,那么接下来就讲一下我们如何将之投入使用.vsphere的虚拟机管理程序就是esxi. 什么是ESXI? vSphere产品套件的核心产品是虚拟机管理程序,作 ...
- golang中特殊的标识符
你会发现在 Go 代码中的几乎所有东西都有一个名称或标识符.另外,Go 语言也是区分大小写的,这与 C 家族中的其它语言相同.有效的标识符必须以字符(可以使用任何 UTF-8 编码的字符或 _)开头, ...
- 盘点Apache毕业的11个顶级项目
自1999年成立至今,Apache 软件基金会已成功建立起自己强大的生态圈.其社区涌现了非常多优秀的开源项目,同时有越来越多国内外项目走向这个国际开源社区进行孵化.据悉,目前所有的 Apache 项目 ...
- IntelliJ Idea 复制粘贴的问题
分析 尝试从外部复制内容向Idea工作空间内粘贴文件时,有一定的几率会发生复制粘贴失败的问题:复制了新的内容,粘贴的却还是早些时候复制的旧的内容. 我使用的IDEA是最新版(2016.1.3),操作系 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十章:混合
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十章:混合 代码工程地址: https://github.com/j ...
- a configuration error occured during startup.please verify the preference field with the prompt:
Window->Preferences->MyEclipse Enterprice Workbench->Servers->Tomcat->选择你的Tomcat(比如To ...
- 【NS2】用eclipse调试NS2(转载)
相信很多喜欢Java的人对eclipse都情有独钟.NS2程序的调试,可以用打印命令调试,这样太繁琐.也可以用gdb调试,个人觉得上手比较困难.相信各位学习NS2的新手,在看代码的时候,很多的函数或者 ...
- Spring中配置DataSource数据源的几种选择
从JNDI获得DataSource. 从第三方的连接池获得DataSource. 使用DriverManagerDataSource获得DataSource. 一.从JNDI获得DataSource ...
- 高可用Kubernetes集群原理介绍
■ 文/ 天云软件 云平台开发工程师 张伟 1. 背景 Kubernetes作为容器应用的管理中心,对集群内部所有容器的生命周期进行管理,结合自身的健康检查及错误恢复机制,实现了集群内部应用层的高可用 ...