【Aactiviti7从⼊门到放弃】(⼀)Activiti7⼯作流引擎⼊门⽬录
4.3 SpringBoot2与Activiti7整合
官⽅⽂档
activiti.gitbook.io/activiti-7-developers-guide/getting-started/getting-started-activiti-core
github/Activiti/Activiti
4.3.1 创建项⽬
命名:springboot-activiti7
4.3.2 Maven依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
xsi="/2001/XMLSchema-instance"
schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.edcode.activiti</groupId>
<artifactId>springboot-activiti7</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/><!-- lookup parent from repository -->
</parent>
<properties>
<mavenpiler.source>8</mavenpiler.source>
<mavenpiler.target>8</mavenpiler.target>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- github/Activiti/Activiti -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.1.0.M4</version>
</dependency>
<dependency>
<groupId>org.activiti.dependencies</groupId>
<artifactId>activiti-dependencies</artifactId>
<version>7.1.0.M4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId&ator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.3.l
server:
port:8080
servlet:
context-path: /
spring:
datasource:
# 数据源
url: jdbc:mysql://${MYSQL_HOST:127.0.0.1}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:activity}?autoReconnect=true&useUnicode=true&character Encoding=utf8&useSSL=false
username: ${MYSQL_USERNAME:root}
password: ${MYSQL_PASSWORD:123456}
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: sql.cj.jdbc.Driver
# 连接池
hikari:
maximum-pool-size:8
minimum-idle:4
idle-timeout:30000
connection-timeout:30000
max-lifetime:45000
auto-commit:true
pool-name: ScaCommerceHikariCP
redis:
database:0
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
timeout:5000
# ⽇志的相关配置
activiti:
history-level: full
db-history-used:true
# ⾃动部署验证设置:true-开启(默认)、false-关闭
check-process-definitions:false
createprocessa4.3.4 启动项⽬
如图,⾃动创建数据库表
4.3.4 ⼿动添加两张数据表,是M4版本缺陷
-- auto-generated definition
-- create schema `test-activity` collate utf8mb4_unicode_ci;
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- 创建⽤户表
-- ----------------------------
DROP TABLE IF EXISTS`user`;
CREATE TABLE`user`(
`id`bigint(20)NOT NULL AUTO_INCREMENT,
`name`varchar(32)DEFAULT NULL COMMENT'姓名',
`address`varchar(64)DEFAULT NULL COMMENT'联系地址',
`username`varchar(255)CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT'账号',
`password`varchar(255)CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT'密码',
`roles`varchar(255)CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT'⾓⾊',
PRIMARY KEY(`id`)
)ENGINE=InnoDB AUTO_INCREMENT=5DEFAULT CHARSET=utf8;
-- ----------------------------
-- 填充⽤户表
-- ----------------------------
INSERT INTO`user`VALUES('1','admincn','beijing','admin','$2a$10$gw46pmsOVYO.smHYQ2jH.OoXoe.lGP8OStDkHNs/E74GqZDL5K7ki','ROLE_ACT IVITI_ADMIN');
INSERT INTO`user`VALUES('2','bajiecn','shanghang','bajie','$2a$10$gw46pmsOVYO.smHYQ2jH.OoXoe.lGP8OStDkHNs/E74GqZDL5K7ki','ROLE_A CTIVITI_USER,GROUP_activitiTeam,g_bajiewukong');
INSERT INTO`user`VALUES('3','wukongcn','beijing','wukong','$2a$10$gw46pmsOVYO.smHYQ2jH.OoXoe.lGP8OStDkHNs/E74GqZDL5K7ki','ROLE_A CTIVITI_USER,GROUP_activitiTeam');
INSERT INTO`user`VALUES('4','salaboycn','beijing','salaboy','$2a$10$gw46pmsOVYO.smHYQ2jH.OoXoe.lGP8OStDkHNs/E74GqZDL5K7ki','ROLE_A CTIVITI_USER,GROUP_activitiTeam');
-- ----------------------------
-- 修复Activiti7的M4版本缺失字段Bug
-- ----------------------------
alter table ACT_RE_DEPLOYMENT add column PROJECT_RELEASE_VERSION_ varchar(255)DEFAULT NULL;
alter table ACT_RE_DEPLOYMENT add column VERSION_ varchar(255)DEFAULT NULL;
-- ----------------------------
-- 动态表单数据存储
-- ----------------------------
DROP TABLE IF EXISTS`formdata`;
CREATE TABLE`formdata`(
`PROC_DEF_ID_`varchar(64)DEFAULT NULL,
`PROC_INST_ID_`varchar(64)CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`FORM_KEY_`varchar(255)DEFAULT NULL,
`Control_ID_`varchar(100)DEFAULT NULL,
`Control_VALUE_`varchar(2000)DEFAULT NULL
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
4.4 流程部署 - Deployment
Deployment 定义
添加资源⽂件、获取部署信息、部署时间
参考⽂档
4.4.1 涉及到的数据表
ACT_RE_DEPLOYMENT
ACT_RE_PROCDEF
ACT_GE_BYTEARRAY
4.4.2 通过bpmn部署流程
@Autowired
private RepositoryService repositoryService;
@Test
public void initDeploymentBPMN(){
String filename ="BPMN/Part1_l";
// String pngname="BPMN/Part1_Deployment.png";
Deployment deployment = ateDeployment()
.addClasspathResource(filename)
// .addClasspathResource(pngname)
.name("流程部署测试BPMN_v2")
.deploy();
System.out.Name());
}
Part1_Deployment.png ⽣成,对着流程图右键:Save to PNG 即可
4.4.3 通过ZIP部署流程
@Autowired
private RepositoryService repositoryService;
@Test
public void initDeploymentZIP(){
InputStream fileInputStream =Class()
.getClassLoader()
.getResourceAsStream("BPMN/Part1_DeploymentV2.zip");
assert fileInputStream != null;
ZipInputStream zip =new ZipInputStream(fileInputStream);
Deployment deployment = ateDeployment()
.addZipInputStream(zip)
.name("流程部署测试zip")
.deploy();
System.out.Name());
}
对住需要压缩的⽂件 Part1_l、Part1_DeploymentV2.png 右键压缩成 zip 即可
4.4.4 查询流程部署
@Autowired
private RepositoryService repositoryService;
@Test
public void getDeployments(){
System.out.println("Id:"+ Id());
System.out.println("Name:"+ Name());
System.out.println("DeploymentTime:"+ DeploymentTime());
System.out.println("Key:"+ Key()+"\n\r");
});
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论