這篇文章將為大家詳細(xì)講解有關(guān)SpringBoot1.5.9如何集成Activiti6,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
成都創(chuàng)新互聯(lián)自2013年起,先為安遠(yuǎn)等服務(wù)建站,安遠(yuǎn)等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為安遠(yuǎn)企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
1.通過(guò)以下地址創(chuàng)建基于Maven的SpringBoot Web項(xiàng)目
https://start.spring.io/
2.添加項(xiàng)目的依賴文件
pom.xml文件如下
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">
3.添加業(yè)務(wù)流程文件
在src/main/java/resource目錄下創(chuàng)建processes目錄
創(chuàng)建process.bpmn文件,內(nèi)容如下
4.配置application.properties文件
配置內(nèi)容如下
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/activiti?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=123456
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.show-sql=true
server.port=8082
server.context-path=/
server.session.timeout=10
server.tomcat.uri-encoding=UTF-8
5.代碼實(shí)現(xiàn)
a.定義接口
package com.springboot.demo.service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/activityConsumerService")
public interface ActivityConsumerService {
@RequestMapping(value = "/startActivityDemo",method = RequestMethod.GET)
public boolean startActivityDemo();
}
b.實(shí)現(xiàn)接口
package com.springboot.demo.service.impl;
import com.springboot.demo.service.ActivityConsumerService;
import org.activiti.engine.RepositoryService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @ClassName ActivityConsumerServiceImpl
* @Description TODO
* @Author yunshuodeng
* @Date 2019-04-29 13:28
* @Version 1.0
**/
@Service("activityService")
public class ActivityConsumerServiceImpl implements ActivityConsumerService {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private RepositoryService repositoryService;
@Override
public boolean startActivityDemo() {
// 獲取當(dāng)前方法名
String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
// 定義任務(wù)辦理人
String name1 = "zhangsan";
String name2 = "lisi";
System.out.println("method " + methodName + " begin ...");
// 輸出流程部署數(shù)量
System.out.println("調(diào)用流程存儲(chǔ)服務(wù),查詢部署數(shù)量" + repositoryService.createDeploymentQuery().count());
Map
map.put("apply",name1);
map.put("approve",name2);
// 流程啟動(dòng)
ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.startProcessInstanceByKey("leave",map);
// 查詢name1的任務(wù)列表
List
// 輸出任務(wù)數(shù)量
System.out.println(taskList.size());
if (taskList != null && taskList.size() > 0){
for (Task task : taskList){
System.out.println("任務(wù)ID:"+task.getId());
System.out.println("任務(wù)辦理人:"+task.getAssignee());
System.out.println("任務(wù)名稱:"+task.getName());
System.out.println("任務(wù)創(chuàng)建時(shí)間:"+task.getCreateTime());
System.out.println("流程實(shí)例ID:"+task.getProcessDefinitionId());
System.out.println("-------------------------------------------");
}
}
System.out.println("method " + methodName + " end ...");
return false;
}
}
6.啟動(dòng)服務(wù)并通過(guò)以下地址進(jìn)行訪問(wèn)
http://localhost:8082/activityConsumerService/startActivityDemo
7.查看控制臺(tái)輸出內(nèi)容并不報(bào)錯(cuò)表示已整合完成
關(guān)于“SpringBoot1.5.9如何集成Activiti6”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。