SpringCloud整合Activiti过程中的踩坑记录
作者:l去留无心
前言
最近需要用到工作流,选择了Activiti,刚开始配置起来并没有很顺利。记录一下希望对读者们有帮助。
先来看我这边项目的环境:主要为JDK1.8,SpringbBoot2.3.5,MyBatis-Plus3.3.2,
MySql8.0.21,Shiro1.5.3,idea 2019.3
<java.version>1.8</java.version> <spring.cloud.version>Hoxton.SR9</spring.cloud.version> <spring.boot.version>2.3.5.RELEASE</spring.boot.version> <ali.cloud.version>2.2.1.RELEASE</ali.cloud.version> <ali.druid.version>1.1.13</ali.druid.version> <mybatis.plus.version>3.3.2</mybatis.plus.version> <mysql.version>8.0.21</mysql.version> <shiro.version>1.5.3</shiro.version>
关于Activiti的配置文件,在nacos中管理yml
数据库参数配置文件
spring: datasource: type: com.alibaba.druid.pool.DruidDataSource druid: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://locahost:3306/activiti_test?useUnicode=true&characterEncoding=UTF-8 username: developer password: developer initial-size: 10 max-active: 100 min-idle: 10 max-wait: 60000 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000
activiti配置文件
spring: activiti: #1.flase: 默认值。activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常 #2.true: activiti会对数据库中所有表进行更新操作。如果表不存在,则自动创建 #3.create_drop: 在activiti启动时创建表,在关闭时删除表(必须手动关闭引擎,才能删除表) #4.drop-create: 在activiti启动时删除原来的旧表,然后在创建新表(不需要手动关闭引擎) database-schema-update: true #检测历史表是否存在 db-history-used: true #记录历史等级 可配置的历史级别有none, activity, audit, full history-level: full #校验流程文件,默认校验resources下的processes文件夹里的流程文件 check-process-definitions: false
理想情况下,当启动项目后,会自动生成25张表。
错误一:shiro与serurity冲突
引用Activiti7.1.0.M6
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-spring-boot-starter --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter</artifactId> <version>7.1.0.M6</version> </dependency>
发现启动报错。报错信息如下:
Description:
The bean 'securityManager', defined in class path resource [org/activiti/core/common/spring/security/config/ActivitiSpringSecurityAutoConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [com/lidomtech/erp/admin/modules/security/config/ShiroConfig.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Disconnected from the target VM, address: '127.0.0.1:5571', transport: 'socket'
Process finished with exit code 0
很明显,这里提示ActivitiSpringSecurityAutoConfiguration与ShiroConfig冲突了。小编项目里面运用的是Shiro,而Activiti默认引用了SpringSecurity。
处理:在启动类屏蔽SpringSecurity
@SpringBootApplication(exclude = { org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class, org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class })
小编心想,可以启动成功了吧!
再次运行,没成想,又报了同样的错误!!这回纳闷了,是不是版本太高了?经查阅,原来Activiti强引用了SpringSecurity里的内容,强引用UserDetailsService, 所以我们还需要把版本降到7.1.0.M4及以下。
处理:更换版本7.1.0.M4及以下
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-spring-boot-starter --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter</artifactId> <version>7.1.0.M2</version> </dependency>
这回可以了吧?!
再次运行
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder.getLanguageDriver(MybatisMapperAnnotationBuilder.java:371)
The following method did not exist:
com.baomidou.mybatisplus.core.MybatisConfiguration.getLanguageDriver(Ljava/lang/Class;)Lorg/apache/ibatis/scripting/LanguageDriver;
啊这,与mybatisplus冲突
错误二:与mybatis冲突
经查官网,activiti会有默认的MyBatis连接池设置,需要讲其依赖的MyBatis注释,才不会引项目中的MyBatis冲突
处理:注释包中的MyBatis
<dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> </exclusions> <version>7.1.0.M2</version> </dependency>
接着,再次启动,启动成功!
顺利生成25张表
关于idea插件
idea里面的直接搜索,对2020.3版本不兼容(建议使用2019版本),可以在https://plugins.jetbrains.com/下载再引进idea
下载好后,在idea的File---->Settings---->Plugins---->
重启后,新增能看到这个说明安装成功
总结
到此这篇关于SpringCloud整合Activiti踩坑的文章就介绍到这了,更多相关SpringCloud整合Activiti踩坑内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!