前言
最近在springboot整合mybatisPlus和activiti6.0过程踩了了很多坑,所以本文做下记录。
正文
依赖的Jar包详情:
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.0</version>
</dependency>
<!--activiti-->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>6.0.0</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
<scope>runtime</scope>
</dependency>
配置信息:
数据库链接信息:
url: jdbc:mysql://47.103.5.190:3306/gourdhu?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false driver-class-name: com.mysql.cj.jdbc.Driver username: root password: xxx
activiti工作流信息
spring: # 工作流 activiti: # 自动部署验证设置: # true(默认)自动部署流程 # false 不自动部署,需要手动部署发布流程 check-process-definitions: true # 可选值为: false,true,create-drop,drop-create # 默认为true。为true表示activiti会对数据库中的表进行更新操作,如果不存在,则进行创建。 database-schema-update: true
报错一:
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)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:51)
原因:
GlobalAuthenticationConfigurerAdapter 这个是在 spring-boot-starter-security 依赖中的 属于安全配置类, 而 引入的activiti-spring-boot-starter-basic 依赖中也存在了一个自动安全配置类, 两个安全配置。
解决:
排除activiti-spring-boot-starter-basic安全配置类
@SpringBootApplication(exclude={
org.activiti.spring.boot.SecurityAutoConfiguration.class
})
报错二:
流程文件找不到
Caused by: java.io.FileNotFoundException: class path resource [processes/] cannot be resolved to URL because it does not exist
at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195)
原因:
如果spring.activiti.check-process-definitions配置设置为true,项目启动会校验部署流程,所以如果没有找到流程文件会报此错误。
解决:
在resource目录下新建processes文件夹(activiti默认访问此文件下的流程文件),并新增bpm流程文件。
或者配置改为false,但是项目启动不会自动部署流程,需要代码中手动部署。
报错三:
无法自动生成activiti表,报错表不存在。
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Table 'gourdhu.ACT_GE_PROPERTY' doesn't exist
### The error may exist in org/activiti/db/mapping/entity/Property.xml
### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntityImpl.selectProperty-Inline
### The error occurred while setting parameters
### SQL: select * from ACT_GE_PROPERTY where NAME_ = ?
### Cause: java.sql.SQLSyntaxErrorException: Table 'gourdhu.ACT_GE_PROPERTY' doesn't exist
原因:https://blog.csdn.net/jiaoshaoping/article/details/80748065
解决:
数据库链接url增加 &nullCatalogMeansCurrent=true
url: jdbc:mysql://47.103.5.190:3306/gourdhu?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=false&nullCatalogMeansCurrent=true
报错四:
报错mybatis的LanguageDriver类找不到
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:369)
The following method did not exist:
com.baomidou.mybatisplus.core.MybatisConfiguration.getLanguageDriver(Ljava/lang/Class;)Lorg/apache/ibatis/scripting/LanguageDriver;
原因:
activiti包中的 org.mybatis 包 和 mybatisPlus中的org.mybatis 包冲突。
解决:
排除掉activiti包中的 org.mybatis 包
<!--activiti-->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>${activiti.version}</version>
<exclusions>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>
springboot2.0整合activiti6.0具体案例请移步:https://blog.csdn.net/HXNLYW/article/details/103005400