SpringBoot2整合activiti6环境搭建
依赖
1<dependencies> 2 <dependency> 3 <groupId>org.springframework.boot</groupId> 4 <artifactId>spring-boot-starter-web</artifactId> 5 </dependency> 6 <dependency> 7 <groupId>org.activiti</groupId> 8 <artifactId>activiti-spring-boot-starter-basic</artifactId> 9 <version>${activiti.version}</version> 10 </dependency> 11 <dependency> 12 <groupId>org.springframework.boot</groupId> 13 <artifactId>spring-boot-starter-jdbc</artifactId> 14 </dependency> 15 <!-- mysql驱动 --> 16 <dependency> 17 <groupId>mysql</groupId> 18 <artifactId>mysql-connector-java</artifactId> 19 </dependency> 20 </dependencies>
这里使用的springboot2.0.6的版本,activiti为6.0.0的版本
添加processes目录

SpringBoot集成activiti默认会从classpath下的processes目录下读取流程定义文件,所以需要在src/main/resources目录下添加processes目录,并在目录中创建流程文件
application.yml
1spring: 2 activiti: 3 check-process-definitions: true #自动检查、部署流程定义文件 4 database-schema-update: true #自动更新数据库结构 5 #流程定义文件存放目录 6 process-definition-location-prefix: classpath:/processes/ 7 #process-definition-location-suffixes: #流程文件格式 8 datasource: 9 driver-class-name: com.mysql.jdbc.Driver 10 url: jdbc:mysql://127.0.0.1:3306/taosir_process?useUnicode=true&useSSL=false&characterEncoding=utf8 11 username : root 12 password : root 13 initsize : 10 14 maxActive : 20 15 minIdle : 10 16 maxWait : 120000 17 poolPreparedStatements : false 18 maxOpenPreparedStatements : -1 19 validationQuery : select 1 20 testOnborrow : true 21 testOnReturn : true 22 testWhileIdle : true 23 timeBetweenEvictionRunsMillis : 120000 24server: 25 port: 8764
bpmn文件
1<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 2<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="Examples" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1539757531057" name="" targetNamespace="Examples" typeLanguage="http://www.w3.org/2001/XMLSchema"> 3 <process id="oneTaskProcess" isClosed="false" name="The One Task Process" processType="None"> 4 <startEvent id="theStart"/> 5 <sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask"/> 6 <userTask activiti:assignee="${user}" activiti:exclusive="true" id="theTask" name="my task"/> 7 <sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd"/> 8 <endEvent id="theEnd"/> 9 </process> 10</definitions>
启动类,注意@SpringBootApplication注解需要设置exclude属性
1package cn.zytao.taosir.process; 2 3import org.activiti.spring.boot.SecurityAutoConfiguration; 4import org.springframework.boot.SpringApplication; 5import org.springframework.boot.autoconfigure.SpringBootApplication; 6 7@SpringBootApplication(exclude = SecurityAutoConfiguration.class) 8public class ProcessApplication { 9 public static void main(String[] args) { 10 SpringApplication.run(ProcessApplication.class, args); 11 } 12}