springboot整合activiti6.0

1 首先引入activiti依赖


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>org.springframework.bootgroupId>
		<artifactId>spring-boot-starter-parentartifactId>
		<version>2.2.5.RELEASEversion>
		<relativePath/> 
	parent>
	<groupId>com.wukgroupId>
	<artifactId>activitiartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<name>activiti-demoname>
	<description>Demo project for Spring Bootdescription>

	<properties>
		<java.version>1.8java.version>
	properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-webartifactId>
		dependency>
		<dependency>
			<groupId>org.activitigroupId>
			<artifactId>activiti-spring-boot-starter-basicartifactId>
			<version>6.0.0version>
		dependency>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-data-jpaartifactId>
		dependency>
		<dependency>
			<groupId>mysqlgroupId>
			<artifactId>mysql-connector-javaartifactId>
			<scope>runtimescope>
		dependency>
	dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.bootgroupId>
				<artifactId>spring-boot-maven-pluginartifactId>
			plugin>
		plugins>
	build>

project>

2 application.yml配置

spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/activiti?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    type: com.zaxxer.hikari.HikariDataSource
    hikari:
      minimum-idle: 5
      ## 空闲连接存活最大时间,默认600000(10分钟)
      idle-timeout: 600000
      ## 连接池最大连接数,默认是10
      maximum-pool-size: 100
      ## 此属性控制从池返回的连接的默认自动提交行为,默认值:true
      auto-commit: true
      ## 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
      max-lifetime: 1800000
      ## 数据库连接超时时间,默认30秒,即30000
      connection-timeout: 30000
      connection-test-query: SELECT 1

  jpa:
    database: mysql
    generate-ddl: false
    hibernate:
      ddl-auto: none
      naming:
        physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
    show-sql: true
    database-platform: org.hibernate.dialect.MySQL55Dialect
    open-in-view: false
activiti:
  database-schema-update: true
    ## 不加载bpmn文件
  check-process-definitions: false 

3 启动类

package com.example.demo;

import org.activiti.spring.boot.SecurityAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication( exclude = SecurityAutoConfiguration.class)
public class ActivitiDemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(ActivitiDemoApplication.class, args);
	}

}

注意的问题

1. 启动类上主要排除冲突类

@SpringBootApplication( exclude = SecurityAutoConfiguration.class)

否则就报错:
springboot整合activiti6.0_第1张图片2. 如果使用的数据库版本是8.0,第一次启动可能会出现如下问题

Cause: java.sql.SQLSyntaxErrorException: Table '*.act_ge_property' doesn't exist

原因:
原因是mysql版本问题,mysql8.xxx以上驱动会出现这个问题,因为mysql使用schema标识库名而不是catalog,因此mysql会扫描所有的库来找表,如果其他库中有相同名称的表,activiti就以为找到了,本质上这个表在当前数据库中并不存在。
设置nullCatalogMeansCurrent=true,表示mysql默认当前数据库操作,在mysql-connector-java 5.xxx该参数默认为true,在6.xxx以上默认为false,因此需要设置nullCatalogMeansCurrent=true。
解决方法:
添加:&nullCatalogMeansCurrent=true

jdbc:mysql://127.0.0.1:3306/activiti?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true

3 默认加载bpmn的路径如下:
目录名称为processes
springboot整合activiti6.0_第2张图片
否则报错如下:
在这里插入图片描述

你可能感兴趣的:(后台,java)