SpringCloud整合Activiti过程中的踩坑记录
前言
最近需要用到工作流,选择了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踩坑内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!