activiti7_工作流开发环境搭建
一、概述
前置条件:
1. 开发软件:idea
2. idea安装actiBPM插件
搭建说明:
1. 本次搭建选用目前最新的开源版本,activiti:7.1.0.M5
2. jdk1.8版本
3. 使用springboot搭建
环境搭建
1. pom文件,引入所需依赖
- 注意这里并没有直接采用activiti官网的activiti-spring-boot-starter的方式,是因为采用官方的starter的方式会默认引入springsecurity相关的jar包,加入spring security 相关的安全特性。
- 虽然说没有采用官方的starter,但是在项目的pom文件里还是使用了activiti官方提供的<dependencyManagement>来框定activiti工作流的版本和springBoot版本。
- 由于activiti7默认会依赖spring,所以activiti 的dependencyManagement会自己管理springBoot版本,本文介绍的activiti7.1.0.M5使用的springBoot版本为springBoot2.1.10.RELEASE。
- 这里只引用了activiti-engine一个依赖
<?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.zhang</groupId>
<artifactId>activity</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>activity</name>
<description>Demo project for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.activiti.dependencies</groupId>
<artifactId>activiti-dependencies</artifactId>
<version>7.1.0.M5</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. 配置数据源
这里采用druid数据源,maven依赖见上面的pom文件,配置如下
spring:
application:
name:server: activity
port: 8080
#数据源配置
datasource:
url: jdbc:mysql://localhost:3306/activity?useUnicode=true&characterEncoding=utf8
driver-class-name: com.mysql.jdbc.Driver
username: xxxx
password: xxxx
type: com.alibaba.druid.pool.DruidDataSource
/**
* 数据源
* @return
*/
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource dataSource(){
return new DruidDataSource();
}
activiti流程引擎相关配置
/**
* 工作流流程引擎配置文件
* @param dataSource
* @return
*/
@Bean
public ProcessEngineConfiguration processEngineConfiguration(DataSource dataSource){
StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
standaloneProcessEngineConfiguration.setDataSource(dataSource);
//自动更新表结构,数据库表不存在时会自动创建表
standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate("true");
//保存历史数据级别设置为full最高级别,便于历史数据的追溯
standaloneProcessEngineConfiguration.setHistoryLevel(HistoryLevel.FULL);
//关闭activiti自动部署(使用流程设计器部署,不使用具体文件访问方式)
standaloneProcessEngineConfiguration.setDbHistoryUsed(true);
return standaloneProcessEngineConfiguration;
}
/**
* 工作流流程引擎
* @param processEngineConfiguration
* @return
*/
@Bean
public ProcessEngine processEngine(ProcessEngineConfiguration processEngineConfiguration){
return processEngineConfiguration.buildProcessEngine();
}
/**
* RuntimeService
* @param processEngine
* @return
*/
@Bean
public RuntimeService runtimeService(ProcessEngine processEngine){
return processEngine.getRuntimeService();
}
/**
* TaskService
* @param processEngine
* @return
*/
@Bean
public TaskService taskService(ProcessEngine processEngine){
return processEngine.getTaskService();
}
/**
* RepositoryService
* @param processEngine
* @return
*/
@Bean
public RepositoryService repositoryService(ProcessEngine processEngine){
return processEngine.getRepositoryService();
}
/**
* HistoryService
* @param processEngine
* @return
*/
@Bean
public HistoryService historyService(ProcessEngine processEngine) {
return processEngine.getHistoryService();
}
完结
启动springboot项目,在查看数据库连接工具。
查看25张数据表,已创建成功。
25张activiti工作流生成的数据表.png
在部署流程的时候会遇到ac_re_deplloment表没有version_字段的异常,自己手工添加相应的自动即可。
网友评论