Flowable深入淺出-5 Flowable-Modeler詳述之開發環境搭建
5 Flowable-Modeler詳述之搭建開發環境
前言
-
Flowable的modeler的環境已經搭建完成,並且可以繪製modeler模型了,我們繪製一個簡單的流程只有開始和結束的流程節點。
-
加入啟動類,自動引入相關的使用的包。
環境搭建
-
安裝jdk
建議使用jdk 8
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
安裝完成後配置java環境變數,這個將bin的環境變數配置到PATH中即可,網上同類教程很多,此處不贅述 -
安裝mysql 5.7
下載mysql 建議5.7版本以上,安裝步驟也是一步步next,不在此處贅述
下載地址:
https://dev.mysql.com/downloads/mysql/ -
安裝idea
安裝idea社群版本,下載地址如下,安裝步驟一步步next
https://www.jetbrains.com/idea/download/ -
新建maven工程
File-New Project,工程名為flowablestudy
-
配置maven,並且建議使用阿里的倉庫,maven的下載地址如下:
http://maven.apache.org/download.cgi
maven的配置 conf/settings.xml配置新增本地倉庫如下:
<localRepository>D:/program/apache-maven-3.6.0/mvnlib</localRepository>
mirrors中新增阿里伺服器
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</ url>
</mirror>
在idea中點選File->Settings,按如下操作:
-
新增一個模組作為工程的一個子模組,在工程上點選右鍵,New->Module,配置模組如下:
-
父pom中配置springboot的pom檔案
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath />
</parent>
引入啟動依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 加入我們的核心依賴,flowable的啟動依賴
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter</artifactId>
<version>6.4.0</version>
</dependency>
- 新增一個controller用來測試流程是否啟動成功
package com.hyj.controller;
@Controller
@RequestMapping(value = "flow")
public class FlowController {
/**
* 日誌類
*/
private static final Logger log = LoggerFactory.getLogger(FlowController.class);
/**
* 流程處理服務
*/
@Autowired
private IFlowService flowService;
@RequestMapping("/create")
@ResponseBody
public Map<String,String> createFlow(){
Map<String,String> res =new HashMap<>();
String flowPath ="E:\\flowablestudy\\flowablech5\\src\\main\\resources\\flows\\測試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;
}
}
- 新增service和serviceimpl檢視提供流程的一些服務,本次只有一個啟動流程的服務
package com.hyj.service;
/**
* 流程服務類
*/
public interface IFlowService {
/**
* 部署工作流
*/
Deployment createFlow(String filePath);
}
實現類
package com.hyj.serviceImpl;
@Primary
@Service
public class FlowServiceImpl implements IFlowService {
/**
* 日誌類
*/
private static final Logger log = LoggerFactory.getLogger(FlowServiceImpl.class);
/**
* Flowable執行時服務
*/
@Autowired
private RepositoryService repositoryService;
@Override
public 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);
}
}
}
}
- 增加啟動類掃描我們的包
package com.hyj.main;
//掃描Service
@ComponentScan(basePackages = { "com.hyj.**" })
//掃描Mapper
@MapperScan(basePackages = {"com.hyj.**"})
@SpringBootApplication
public class App {
private final static Logger logger = LoggerFactory.getLogger(App.class);
public static void main(String[] args) {
logger.info("開始啟動服務 ");
SpringApplication.run(App.class, args);
logger.info("完成啟動服務 ");
}
}
- 配置啟動項
server:
port: 8989
tomcat:
# tomcat的URI編碼
uri-encoding: UTF-8
# tomcat最大執行緒數,預設為200
max-threads: 200
# Tomcat啟動初始化的執行緒數,預設值25
min-spare-threads: 30
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.hyj # 注意:對應實體類的路徑
# 資料來源配置
spring:
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/flowstudy?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&&zeroDateTimeBehavior=convertToNull&useSSL=true&allowMulQueries=true&&nullCatalogMeansCurrent=true
username: root
password: root
- 建立一個mysql資料庫,flowstudy,設定編碼為UTF-8
CREATE DATABASE /*!32312 IF NOT EXISTS*/`flowstudy` /*!40100 DEFAULT CHARACTER SET utf8 */;
-
啟動服務,啟動的時候會自動建立我們需要的表,如果另外一個activity的示例安裝過資料庫,注意配置上面的啟動項的引數,設定nullCatalogMeansCurrent=true,啟動建表列印如下:
-
mysql中的表如下:
-
測試檢視建立結果
-
檢視流程在表中的內容
部署ID表act_re_deployment
部署內容表:act_ge_bytearray
-
程式碼下載地址
https://download.csdn.net/download/houyj1986/10889089 -
使用的流程檔案如下:
<?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:flowable="http://flowable.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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef">
<process id="test_bpmn" name="測試BPMN模型" isExecutable="true">
<documentation>測試BPMN模型</documentation>
<startEvent id="start" name="開始"></startEvent>
<endEvent id="end" name="結束"></endEvent>
<userTask id="testUser" name="使用者任務測試"></userTask>
<sequenceFlow id="sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002" sourceRef="start" targetRef="testUser"></sequenceFlow>
<sequenceFlow id="sid-AB59612A-1B33-4FB8-8758-5D773EDF9C44" sourceRef="testUser" targetRef="end"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_test_bpmn">
<bpmndi:BPMNPlane bpmnElement="test_bpmn" id="BPMNPlane_test_bpmn">
<bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
<omgdc:Bounds height="30.0" width="30.0" x="210.0" y="60.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
<omgdc:Bounds height="28.0" width="28.0" x="525.0" y="61.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="testUser" id="BPMNShape_testUser">
<omgdc:Bounds height="80.0" width="100.0" x="315.0" y="35.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002" id="BPMNEdge_sid-8D834F3C-45A8-4C88-9AD1-1AC426CC9002">
<omgdi:waypoint x="239.94999779398907" y="75.0"></omgdi:waypoint>
<omgdi:waypoint x="315.0" y="75.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-AB59612A-1B33-4FB8-8758-5D773EDF9C44" id="BPMNEdge_sid-AB59612A-1B33-4FB8-8758-5D773EDF9C44">
<omgdi:waypoint x="414.9499999999903" y="75.0"></omgdi:waypoint>
<omgdi:waypoint x="525.0" y="75.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
打賞
如果您覺得該文章對您有幫助,歡迎打賞作者,謝謝。
版權
版權所有,侵權必究,程式碼與文章,使用、copy、轉載請聯絡作者。由書山登峰人創作。