[TOC]
## 1、搭建maven聚合工程
> 为了以后扩展方便,再此我们搭建一个聚合工程。
### 1.1 框架搭建
![](https://img.kancloud.cn/4b/ee/4bee507ba8a48022882b5b6b7e40a2c3_1456x735.png)
![](https://img.kancloud.cn/fe/16/fe16e5fa9152bb0b37528dc1aff13b5b_1457x734.png)
删除src目录
![](https://img.kancloud.cn/83/b0/83b088a591756e4a4f04a8832424ffeb_1665x557.png)
创建一个module工程
![](https://img.kancloud.cn/dc/3d/dc3d03d078d3f66266d0e914065b676f_1466x748.png)
![](https://img.kancloud.cn/19/29/19295ef7e48c3bba9c157e1ad1c26e37_1458x752.png)
目录结构如下:
![](https://img.kancloud.cn/ed/17/ed1701301f4417957d9b9040e87b694d_649x505.png)
### 1.2 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>org.sxdx</groupId>
<artifactId>workflow-activiti</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>workflow-activiti-rest</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<druid.version>1.1.14</druid.version>
<swagger.version>2.9.2</swagger.version>
<fastjson.version>1.2.68</fastjson.version>
<activiti.version>6.0.0</activiti.version>
</properties>
<!-- 依赖声明 -->
<dependencyManagement>
<dependencies>
<!-- SpringBoot的依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--阿里数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- swagger2-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- swagger2-UI-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- 阿里JSON解析器 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
~~~
* workflow-activiti-rest 子工程
```
<?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>
<artifactId>workflow-activiti</artifactId>
<groupId>org.sxdx</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>workflow-activiti-rest</artifactId>
<dependencies>
<!-- SpringBoot Web容器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- Mysql驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--阿里数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 表示依赖不会传递 -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
<configuration>
<fork>true</fork> <!-- 如果没有该配置,devtools不会生效 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>
</project>
```
## 2、 改成springboot工程
### 2.1 设置启动类
~~~
package com.sxdx.workflow.activiti.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WorkFlowActivitiRestApplication {
public static void main(String[] args)
{
SpringApplication.run(WorkFlowActivitiRestApplication.class, args);
System.out.println("启动成功");
}
}
~~~
### 2.2 application.yml
~~~
# 开发环境配置
server:
# 服务器的HTTP端口,默认为80
port: 8080
servlet:
# 应用的访问路径
context-path: /
tomcat:
# tomcat的URI编码
uri-encoding: UTF-8
# tomcat最大线程数,默认为200
max-threads: 800
# Tomcat启动初始化的线程数,默认值25
min-spare-threads: 30
# Spring配置
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true
username: root
password: gaoyipeng
#druid配置
druid:
# 初始连接数
initialSize: 5
# 最小连接池数量
minIdle: 10
# 最大连接池数量
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
# 配置一个连接在池中最大生存的时间,单位是毫秒
maxEvictableIdleTimeMillis: 900000
# 配置检测连接是否有效
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
webStatFilter:
enabled: true
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username:
login-password:
filter:
stat:
enabled: true
# 慢SQL记录
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
~~~
通过我们上面的配置我们知道需要新建一个名为activiti的mysql数据库。
最终效果如下:
![](https://img.kancloud.cn/b3/6c/b36cbf1d40211f68888b8759fddbae50_1728x641.png)
## 3、启动
访问:[http://localhost:8080/druid](http://localhost:8080/druid)
![](https://img.kancloud.cn/43/fe/43fe1d592f1bc6d21939372555f34e53_2551x1123.png)
## 4、集成activiti6
在workflow-activiti-rest 的pom 文件中添加
~~~
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>${activiti.version}</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-json-converter</artifactId>
<version>6.0.0</version>
<exclusions>
<exclusion>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-model</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- xml解析依赖-->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-codec</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-css</artifactId>
<version> 1.7</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-svg-dom</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-svggen</artifactId>
<version>1.7</version>
</dependency>
~~~
### 4.1 排除 Activiti 和 Spring Security 登录验证
再次启动会报错:
~~~
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.sxdx.workflow.activiti.rest.WorkFlowActivitiRestApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist
......
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
~~~
解决方法:
~~~
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,
org.activiti.spring.boot.SecurityAutoConfiguration.class,
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
})
public class WorkFlowActivitiRestApplication {
public static void main(String[] args)
{
SpringApplication.run(WorkFlowActivitiRestApplication.class, args);
System.out.println("启动成功");
}
}
~~~
### 4.2 application.yml 添加配置
```
# Spring配置
spring:
# activiti 模块
# 解决启动报错:class path resource [processes/] cannot be resolved to URL because it does not exist
activiti:
check-process-definitions: false
```
![](https://img.kancloud.cn/5e/55/5e550ab9993d51de3a5f67fd632727ef_1718x653.png)
## 5、验证
再次启动程序,能够正常启动。
![](https://img.kancloud.cn/3a/e9/3ae9d62d0a8e909767c30bd51cb58bd1_1914x474.png)
这是我们看看数据库:
![](https://img.kancloud.cn/2e/57/2e57b76bf3789fb784f3113002aa6042_1239x661.png)
可以看到自动生成了activiti的28张表。至此,基本环境已经搭建完成。
- 使用教程
- 1、环境说明
- 2、导入教程
- 3、系统展示
- 4、更新历史
- 搭建教程
- 第一章:Activiti模块
- 1、基本概念
- 2、资料下载
- 3、环境搭建
- 4、集成Activiti-Modeler流程设计器
- 5、七大Service接口
- 6、流程定义文件—流程定义—流程模型 的相互转化
- 7、用户和用户组
- 8、任务表单
- 8.1、表单分类
- 8.2 、动态表单实战、集成Swagger、Logback
- 8.3、外置表单实战
- 8.4、普通表单实战,集成Thymeleaf,Mybatis-Plus
- 8.5、表单模式选型
- 9、多实例(会签)
- 10、子流程和调用活动
- 10.1、子流程
- 10.2、事件子流程
- 10.3、调用活动
- 10.4、事务子流程
- 11、流程历史管理、补充获取流程定义列表接口
- 12、Activiti事件
- 12.1、 事件类别
- 12.2、 Activiti启动事件
- 12.3、Activiti结束事件
- 12.4、边界事件(一)
- 12.5、边界事件(二)
- 12.6、中间事件
- 13、网关
- 14、Activiti审批意见管理
- 15、Activiti流程驳回、流程回退
- 16、Activiti任务委托
- 17、Activiti流程的挂起、激活
- 第二章:基础架构完善
- 1、Spring-Security-OAuth2简介
- 2、搭建认证服务器
- 3、搭建资源服务器
- 4、Activiti自带的Rest接口
- 5、添加JWT支持
- 6、数据库存储授权码Code,Client信息
- 第三章、集成RBAC权限管理
- 1、RBAC-基于角色的访问控制
- 2、替换Activiti用户和用户组
- 3、Spring-Security获取当前操作人信息
- 4、OauthUserDetailService改造
- 第四章、使用Swagger生成静态接口文档