springboot2.2.1整合多数据源 mybatis、activiti7

因后台系统审批的越来越多,流程审批变得复杂,所以需引入bpm,当前流程的activiti7.整合到当前系统中。

当前系统使用的是springcloud+springboot+mybatis+stringmvc+swagger2+redis+mongo+......+activi7

因直接把activiti7的数据库引入后,报错,找了好下,才解决问题,特此记录。。

加得再多,也是增加包的引入而已。

依照历史经验,话不多说,直接上代码。

先是原先的多数据源配置。

配置文件配置:

mysql-suvs-conf.yml

#mysql链接
spring:
  datasource:
    biz: 
      jdbc-url: jdbc:mysql://192.168.3.252:3306/chenweixian-biz?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1
    trade: 
      jdbc-url: jdbc:mysql://192.168.3.252:3306/chenweixian-trade?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1
    com: 
      jdbc-url: jdbc:mysql://192.168.3.252:3306/chenweixian-com?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1
    risk: 
      jdbc-url: jdbc:mysql://192.168.3.252:3306/chenweixian-risk?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1
    system: 
      jdbc-url: jdbc:mysql://192.168.3.252:3306/chenweixian-system?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1
    option: 
      jdbc-url: jdbc:mysql://192.168.3.252:3306/chenweixian-option?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1
    sign:
      jdbc-url: jdbc:mysql://192.168.3.252:3306/chenweixian-sign?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1
    flow: 
      jdbc-url: jdbc:mysql://192.168.3.252:3306/active4j-flow?useUnicode=true&autoReconnect=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false
      username: root
      password: root123456
      max-idle: 10 #指定连接池最大的空闲连接数量.
      max-wait: 10000 #指定连接池等待连接返回的最大等待时间,毫秒单位.
      min-idle: 5 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
      initial-size: 5 #指定启动连接池时,初始建立的连接数量
      validation-query: SELECT 1 #指定获取连接时连接校验的sql查询语句.
      test-on-borrow: false #获取连接时候验证,会影响性能
      test-while-idle: true #当连接空闲时,是否执行连接测试.
      time-between-eviction-runs-millis: 18800 #指定空闲连接检查、废弃连接清理、空闲连接池大小调整之间的操作时间间隔
      hikari:
        maximum-pool-size: 2
        minimum-idle: 0 #指定必须保持连接的最小值(For DBCP and Tomcat connection pools)
        connection-test-query: SELECT 1

 

java配置文件

DataSource***Config.java

为了明确数据源DB配置,其中***为具体数据源,比如数据源节点

数据源中flow是activiti的数据库。

其中两个配置

DataSourceBizConfig.java

其他N个服务启动配置都是如此,只需替换biz为节点标签即可。

package com.chenweixian.suvs.config;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import com.chenweixian.suvs.common.constants.DataSourceConstants;
/**
 * 读取biz数据源<br>
 */
@Configuration // 注册到springboot容器中
@MapperScan(basePackages = {"com.chenweixian.suvs.core.biz.mapper","com.chenweixian.suvs.core.biz.mymapper"}, sqlSessionFactoryRef = "bizSqlSessionFactory")
public class DataSourceBizConfig {
 
    /**
     * @methodDesc: 功能描述:(配置biz数据库)
     */
    @Bean(name = "bizDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.biz")
    public DataSource bizDataSource() {
        return DataSourceBuilder.create().build();
    }
 
    /**
     * @methodDesc: 功能描述:(biz sql会话工厂)
     */
    @Bean(name = "bizSqlSessionFactory")
    public SqlSessionFactory bizSqlSessionFactory(@Qualifier("bizDataSource") DataSource dataSource) throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:sqlmapper/**/*.xml"));
        return bean.getObject();
    }
 
    /**
     * @methodDesc: 功能描述:(biz事物管理)
     */
    @Bean(name = DataSourceConstants.BIZ_TRANSACTION_MANAGER)
    public DataSourceTransactionManager bizTransactionManager(@Qualifier("bizDataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
 
    @Bean(name = "bizSqlSessionTemplate")
    public SqlSessionTemplate bizSqlSessionTemplate( @Qualifier("bizSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory);
    }
}

 

DataSourceFlowConfig.java

 这必须指定一个默认数据源,否则activiti启动有问题。加上标签 @Primary

默认数据源需要在如下两个地方配置

package com.chenweixian.suvs.config;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import com.chenweixian.suvs.common.constants.DataSourceConstants;
/**
 * 读取flow数据源<br>
 */
@Configuration // 注册到springboot容器中
@MapperScan(basePackages = {"com.chenweixian.suvs.core.flow.mapper","com.chenweixian.suvs.core.flow.mymapper"}, sqlSessionFactoryRef = "flowSqlSessionFactory")
public class DataSourceFlowConfig {
 
    /**
     * @methodDesc: 功能描述:(配置flow数据库)
     */
    @Primary
    @Bean(name = "flowDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.flow")
    public DataSource flowDataSource() {
        return DataSourceBuilder.create().build();
    }
 
    /**
     * @methodDesc: 功能描述:(flow sql会话工厂)
     */
    @Bean(name = "flowSqlSessionFactory")
    public SqlSessionFactory flowSqlSessionFactory(@Qualifier("flowDataSource") DataSource dataSource) throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:sqlmapper/**/*.xml"));
        return bean.getObject();
    }
 
    /**
     * @methodDesc: 功能描述:(flow事物管理)
     */
    @Primary
    @Bean(name = DataSourceConstants.FLOW_TRANSACTION_MANAGER)
    public DataSourceTransactionManager flowTransactionManager(@Qualifier("flowDataSource") DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean(name = "flowSqlSessionTemplate")
    public SqlSessionTemplate flowSqlSessionTemplate( @Qualifier("flowSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory);
    }
}

 如果没增加@Primary以上标签,那么会提示如下错误:



***************************
APPLICATION FAILED TO START
***************************


Description:


Parameter 0 of method springProcessEngineConfiguration in org.activiti.spring.boot.ProcessEngineAutoConfiguration required a single bean, but 8 were found:
- bizDataSource: defined by method 'bizDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceBizConfig.class]
- comDataSource: defined by method 'comDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceComConfig.class]
- flowDataSource: defined by method 'flowDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceFlowConfig.class]
- optionDataSource: defined by method 'optionDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceOptionConfig.class]
- riskDataSource: defined by method 'riskDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceRiskConfig.class]
- signDataSource: defined by method 'signDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceSignConfig.class]
- systemDataSource: defined by method 'systemDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceSystemConfig.class]
- tradeDataSource: defined by method 'tradeDataSource' in class path resource [com/chenweixian/suvs/config/DataSourceTradeConfig.class]



Action:


Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed


2022-08-17 10:16:36.362 ERROR 7976 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@5a7fe64f] to prepare test instance [com.test.dbtest.FlowTest@3ac6c956]


java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132) ~[spring-test-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123) ~[spring-test-5.2.1.RELEASE.jar:5.2.1.RELEASE]

......
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/D:/my_repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/D:/my_repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webEndpointServletHandlerMapping' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping]: Factory method 'webEndpointServletHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngineEndpoint' defined in class path resource [org/activiti/spring/boot/EndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngineEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngine' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngine' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProcessEngineConfiguration' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springProcessEngineConfiguration' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:787) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 45 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/D:/my_repository/io/springfox/springfox-spring-web/2.9.2/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webEndpointServletHandlerMapping' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping]: Factory method 'webEndpointServletHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngineEndpoint' defined in class path resource [org/activiti/spring/boot/EndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngineEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngine' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngine' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProcessEngineConfiguration' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springProcessEngineConfiguration' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:787) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 63 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webEndpointServletHandlerMapping' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping]: Factory method 'webEndpointServletHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngineEndpoint' defined in class path resource [org/activiti/spring/boot/EndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngineEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngine' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngine' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProcessEngineConfiguration' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springProcessEngineConfiguration' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:645) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 80 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping]: Factory method 'webEndpointServletHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngineEndpoint' defined in class path resource [org/activiti/spring/boot/EndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngineEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngine' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngine' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProcessEngineConfiguration' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springProcessEngineConfiguration' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:640) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 97 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngineEndpoint' defined in class path resource [org/activiti/spring/boot/EndpointAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngineEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngine' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngine' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProcessEngineConfiguration' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springProcessEngineConfiguration' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:787) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:528) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 98 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'processEngine' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'processEngine' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProcessEngineConfiguration' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springProcessEngineConfiguration' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:787) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 118 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springProcessEngineConfiguration' defined in class path resource [org/activiti/spring/boot/ProcessEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'springProcessEngineConfiguration' parameter 0; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
... 132 common frames omitted
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected single matching bean but found 8: bizDataSource,comDataSource,flowDataSource,optionDataSource,riskDataSource,signDataSource,systemDataSource,tradeDataSource
at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:220) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1265) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:874) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:778) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 146 common frames omitted

 

 

启动服务yml配置:

bootstrap.yml

server: 
  port: 10500
spring: 
  application:
    name: chenweixian-suvs-oa
  main:
    #当遇到同样名字的时候,是否允许覆盖注册不配置会报错 
    allow-bean-definition-overriding: true
  jackson:
     #过滤为null的值 需要返回值不为String
#    default-property-inclusion: non_null
    time-zone: GMT+8
  cloud:
    config: 
      name: mysql-suvs
      discovery:
        enabled: true
        service-id: chenweixian-base-config
      profile: conf
#日志级别
logging: 
  level:
    root: info

  file:
    name: /home/logs/${spring.application.name}/${spring.application.name}.log
    max-history: 30
    max-size: 500MB

#注册中心
eureka:
  ip: 192.168.3.252
  instance:
    prefer-ip-address: true
  client: 
    serviceUrl:
      defaultZone: http://${eureka.ip:127.0.0.1}:${eurka.port:8761}/eureka/

 

application.yml

增加spring.activiti节点配置,配置如下

spring: 
  main:
    #当遇到同样名字的时候,是否允许覆盖注册不配置会报错 
    allow-bean-definition-overriding: true
  profiles:
    active: local
  #文件上传大小配置更改
  servlet: 
    multipart: 
      enabled: true
      max-file-size: 50MB  
      max-request-size: 100MB
  #配置信息
  activiti:
    database-schema-update: true
    db-history-used: true
    history-level: full
    check-process-definitions: false
    async-executor-activate: true
      
#日志开关 N不显示
logAspect.showLog: N
#暴露actuator所有接口,否则默认只有3个接口
management:
  endpoints:
    web:
      exposure:
        include: '*'
mybatis:
  configuration:
    #开启驼峰命名法
    map-underscore-to-camel-case: true
    # 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  #xml地址
  mapper-locations: classpath*:sqlmapper/**/*.xml
  # 实体扫描,多个package用逗号或者分号分隔
  type-aliases-package: com.chenweixian.suvs.*.*.dto
    
# pagehelper 分页
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql

项目maven依赖包pom.xml 配置

增加activiti配置

<!-- activiti 整合 -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter</artifactId>
            <version>7.1.0.M2</version>
             <exclusions>
                <exclusion>
                    <groupId>de.odysseus.juel</groupId>
                    <artifactId>juel-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>de.odysseus.juel</groupId>
                    <artifactId>juel-spi</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.el</groupId>
                    <artifactId>el-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

很容易包冲突,如果不排除冲突,那么可能会因为包的版本问题,导致报错,比如标红的el-api。我在别的地方已经引入了


***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

javax.el.ELManager.getExpressionFactory(ELManager.java:38)

The following method did not exist:

javax.el.ELUtil.getExpressionFactory()Ljavax/el/ExpressionFactory;

The method's class, javax.el.ELUtil, is available from the following locations:

jar:file:/D:/my_repository/javax/el/el-api/2.2/el-api-2.2.jar!/javax/el/ELUtil.class
jar:file:/D:/my_repository/org/glassfish/jakarta.el/3.0.3/jakarta.el-3.0.3.jar!/javax/el/ELUtil.class

It was loaded from the following location:

file:/D:/my_repository/javax/el/el-api/2.2/el-api-2.2.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.el.ELUtil

2022-08-17 10:24:32.486 ERROR 24880 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@41330d4f] to prepare test instance [com.test.dbtest.FlowTest@209aefd1]


Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]: Factory method 'defaultValidator' threw exception; nested exception is java.lang.NoSuchMethodError: javax.el.ELUtil.getExpressionFactory()Ljavax/el/ExpressionFactory; at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:640) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] ... 63 common frames omitted Caused by: java.lang.NoSuchMethodError: javax.el.ELUtil.getExpressionFactory()Ljavax/el/ExpressionFactory; at javax.el.ELManager.getExpressionFactory(ELManager.java:38) ~[jakarta.el-3.0.3.jar:na] at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:88) ~[hibernate-validator-6.0.18.Final.jar:6.0.18.Final] at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:47) ~[hibernate-validator-6.0.18.Final.jar:6.0.18.Final] at org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultMessageInterpolator(ConfigurationImpl.java:474) ~[hibernate-validator-6.0.18.Final.jar:6.0.18.Final] at org.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:53) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE] at org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration.defaultValidator(ValidationAutoConfiguration.java:57) ~[spring-boot-autoconfigure-2.2.1.RELEASE.jar:2.2.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] ... 64 common frames omitted

 

接下来是启动测试

BaseTest.java

package com.test;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.chenweixian.SuvsOaApp;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SuvsOaApp.class)
public class BaseTest {

    
    private Long starttime;
    @Rule
    public TestName junitClass= new TestName();
    @Before
    public void before() {
        starttime = System.currentTimeMillis();
        System.out.println(junitClass.getMethodName() + "....................start....................");
    }
    @After
    public void after() {
        double usedtime = (System.currentTimeMillis() - starttime) / 1000.0;
        System.out.println("耗时  " + usedtime + " ms");
        System.out.println(junitClass.getMethodName() + "....................end....................");
    }
    @Test
    public void hello() {
        System.out.println("hello world");
    }
}

FlowTest.java

package com.test.dbtest;

import org.junit.Test;

import com.test.BaseTest;

public class FlowTest extends BaseTest {

    /**
     * 查询一条信息
     *
     * @throws Exception
     */
    @Test
    public void helloTest() throws Exception {
        System.out.println("hello junit5");
    }


}

 能正常输出,说明已整合包成功,接下来就是测试activiti的流程功能。

helloTest....................start....................
hello junit5
耗时  0.004 ms
helloTest....................end....................
2022-08-17 10:29:15.736  INFO 1980 --- [extShutdownHook] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING

 

posted on 2022-08-16 18:09  陈惟鲜的博客  阅读(1297)  评论(0编辑  收藏  举报

导航