接上一篇:
第4篇:Flowable-Modeler详述之流程概述
https://blog.csdn.net/weixin_40816738/article/details/102886712
文章目录
- 一、环境搭建
- 1. 下载/安装jdk
- 2. 安装mysql 5.7
- 3. 安装idea
- 4. 配置maven
- 4.1. 配置maven仓库
- 4.2. mirrors中添加阿里服务器
- 4.3. 在idea中配置maven
- 5. 新建maven工程
- 6. 新建子工程
- 二、依赖引入
- 2.1. 父工程maven依赖
- 2.2. 子工程Maven依赖
- 三 、案例演练
- 3.1. 添加一个controller用来测试流程是否启动成功
- 3.2. 新建接口
- 3.3. 新建逻辑处理类
- 3.4. 增加启动类和包扫描
- 3.5. 配置yml文件
- 3.6. 创建一个mysql数据库
- 3.7. 启动服务
- 3.8. mysql中的表总览
- 3.9. 测试查看创建结果
- 3.10 . 查看流程在表中的内容
前言:
- Flowable的modeler的环境已经搭建完成,并且可以绘制modeler模型了,我们绘制一个简>单的流程只有开始和结束的流程节点。
- 加入启动类,自动引入相关的使用的包。
一、环境搭建
1. 下载/安装jdk
-建议使用jdk 8
JDK环境变量配置_windows
https://blog.csdn.net/weixin_40816738/article/details/102893885
2. 安装mysql 5.7
win10 下安装、配置、启动mysql
https://blog.csdn.net/weixin_40816738/article/details/90112245
3. 安装idea
官网地址:https://www.jetbrains.com/idea/download/
IntelliJ IDEA 2019 下载安装
https://blog.csdn.net/weixin_40816738/article/details/90209326
4. 配置maven
4.1. 配置maven仓库
maven的配置 conf/settings.xml配置添加本地仓库如下:
<localRepository>D:\rep</localRepository>
4.2. mirrors中添加阿里服务器
<mirror><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url><mirrorOf>central</mirrorOf></mirror>
4.3. 在idea中配置maven
点击File->Settings
按如下操作
5. 新建maven工程
【File】-【New Project】-,工程名为 flowablestudy
6. 新建子工程
- 添加一个模块作为工程的一个子模块,在工程上点击右键,New->Module,配置模块如下:
二、依赖引入
2.1. 父工程maven依赖
- pom中配置springboot的pom文件
<?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.gblfy</groupId><artifactId>flowablestudy</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><module>flowablelech5</module></modules><!--springboot 父工程--><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.1.RELEASE</version></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-devtools</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- SpringBoot 拦截器 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.13</version></dependency><dependency><groupId>org.flowable</groupId><artifactId>flowable-spring-boot-starter</artifactId><version>6.4.1</version></dependency><!--常用工具类 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.4</version></dependency><!--集合常用工具类 --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-collections4</artifactId><version>4.2</version></dependency><!--io常用工具类 --><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.5</version></dependency><!--文件上传工具类 --><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.3</version></dependency></dependencies>
</project>
2.2. 子工程Maven依赖
<?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"><parent><groupId>com.gblfy</groupId><artifactId>flowablestudy</artifactId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>flowablelech5</artifactId><dependencies><dependency><groupId>org.flowable</groupId><artifactId>flowable-engine</artifactId><version>6.4.1</version><scope>compile</scope></dependency><dependency><groupId>org.flowable</groupId><artifactId>flowable-spring</artifactId><version>6.4.1</version><scope>compile</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><mainClass>com.gblfy.FlowableApplication</mainClass><includeSystemScope>true</includeSystemScope></configuration><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build>
</project>
三 、案例演练
3.1. 添加一个controller用来测试流程是否启动成功
package com.gblfy.controller;import com.gblfy.service.IFlowService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap;
import java.util.Map;/*** @author gblfy* @ClassNme FlowController* @Description TODO* @Date 2019/11/4 13:58* @version1.0*/
@Controller
@RequestMapping(value = "flow")
public class FlowController {/*** 日志类*/private static final Logger log = LoggerFactory.getLogger(FlowController.class);/*** 流程处理服务*/@Autowiredprivate IFlowService flowService;@RequestMapping("/create")@ResponseBodypublic Map<String,String> createFlow(){Map<String,String> res =new HashMap<>();// String flowPath ="E:\\flowablestudy\\flowablech5\\src\\main\\resources\\flows\\测试BPMN模型.bpmn20.xml";String flowPath ="C:\\Users\\gblfy\\Desktop\\Workflow\\flowablestudy\\flowablelech5\\src\\main\\resources\\processes\\测试BPMN模型.bpmn20.xml";if (null == flowService.createFlow(flowPath)){res.put("msg","创建流程失败");res.put("res","0");return res;}res.put("msg","创建流程成功");res.put("res","1");return res;}
}
3.2. 新建接口
- 添加service查看提供流程的一些服务,本次只有一个启动流程的服务
- IFlowService
package com.gblfy.service;import org.flowable.engine.repository.Deployment;/*** 流程服务类*/
public interface IFlowService {/*** 部署工作流*/Deployment createFlow(String filePath);
}
3.3. 新建逻辑处理类
- FlowServiceImpl
package com.gblfy.service.impl;import com.gblfy.service.IFlowService;
import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.Process;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;/*** @author gblfy* @ClassNme IFlowServiceImpl* @Description TODO* @Date 2019/11/4 14:01* @version1.0*/
@Primary
@Service
public class FlowServiceImpl implements IFlowService {/*** 日志类*/private static final Logger log = LoggerFactory.getLogger(FlowServiceImpl.class);/*** Flowable运行时服务*/@Autowiredprivate RepositoryService repositoryService;@Overridepublic Deployment createFlow(String filePath) {//解析BPMN模型看是否成功XMLStreamReader reader = null;InputStream inputStream = null;try {BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();XMLInputFactory factory = XMLInputFactory.newInstance();inputStream=new FileInputStream(new File(filePath));reader = factory.createXMLStreamReader(inputStream);BpmnModel model = bpmnXMLConverter.convertToBpmnModel(reader);List<Process> processes = model.getProcesses();Process curProcess = null;if (CollectionUtils.isEmpty(processes)) {log.error("BPMN模型没有配置流程");return null;}curProcess = processes.get(0);inputStream=new FileInputStream(new File(filePath));DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name("TEST_FLOW").addInputStream(curProcess.getName(),inputStream);Deployment deployment= deploymentBuilder.deploy();log.warn("部署流程 name:"+curProcess.getName() + " "+deployment);return deployment;}catch (Exception e){log.error("BPMN模型创建流程异常",e);return null;}finally {try {reader.close();} catch (XMLStreamException e) {log.error("关闭异常",e);}}}
}
3.4. 增加启动类和包扫描
package com.gblfy;import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;/*** @author gblfy* @ClassNme FlowableApplication* @Description TODO* @Date 2019/11/4 14:07* @version1.0*/
//扫描Service
@ComponentScan(basePackages = { "com.gblfy.**" })
//扫描Mapper
@MapperScan(basePackages = {"com.gblfy.**"})
@SpringBootApplication
public class FlowableApplication {private final static Logger logger = LoggerFactory.getLogger(FlowableApplication.class);public static void main(String[] args){logger.info("开始启动服务 ");SpringApplication.run(FlowableApplication.class,args);logger.info("完成启动服务 ");}
}
3.5. 配置yml文件
server:port: 8989tomcat:# tomcat的URI编码uri-encoding: UTF-8# tomcat最大线程数,默认为200max-threads: 200# Tomcat启动初始化的线程数,默认值25min-spare-threads: 30mybatis:mapper-locations: classpath:mapper/*.xmltype-aliases-package: com.gblfy # 注意:对应实体类的路径# 数据源配置
spring:datasource:driverClassName: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/flowstudy?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&&zeroDateTimeBehavior=convertToNull&useSSL=true&allowMulQueries=true&&nullCatalogMeansCurrent=trueusername: rootpassword: root
3.6. 创建一个mysql数据库
- flowstudy,设置编码为UTF-8
CREATE DATABASE /*!32312 IF NOT EXISTS*/`flowstudy` /*!40100 DEFAULT CHARACTER SET utf8 */;
3.7. 启动服务
启动的时候会自动创建我们需要的表,如果另外一个activity的示例安装过数据库,注意配置上面的启动项的参数,设置nullCatalogMeansCurrent=true
,启动建表打印如下:
3.8. mysql中的表总览
3.9. 测试查看创建结果
3.10 . 查看流程在表中的内容
- 部署ID表 act_re_deployment
- 部署内容表:act_ge_bytearray
源码地址:
Gitlab链接:
https://gitlab.com/gb-heima/flowablestudy/tree/master/flowablelech5
码云地址:https://gitee.com/gb_90/flowable-study/tree/master/flowablelech5
下一篇:
第6篇:Flowable-Modeler详述之常见问题Table act_ge_property doesn’t exist
https://blog.csdn.net/weixin_40816738/article/details/102899408