集成flowable扫描报错 Mapped Statements collection does not contain value for org.flowable.ui.modeler.dom

项目场景:

springboot+mybatis-plus集成flowable扫描jar包下的xml文件报错,mybatisplus版本是3.5.2

报错信息如下:

Mapped Statements collection does not contain value for org.flowable.ui.modeler.domain.Model.selectModelByParameters

原因为未配置扫描flowable的mapping文件


原因:

这里会有俩个问题,
(1)、是jar包下的xml扫包没扫到.
(2)、是在xml文件还需要一些参数.

在这里插入图片描述


解决方案:

1. yml文件配置

#yml:
mybatis-plus:
  mapper-locations: classpath:/META-INF/modeler-mybatis-mappings/*.xml
  configuration-properties:
    prefix:
    blobType: BLOB
    boolValue: TRUE

这种适用于单数据源场景,原因是在mybatisplus启动类中启动条件是单数据源匹配
@ConditionalOnSingleCandidate 注解用来判断指定类在 BeanFactory 中是否只有一个实例:
(1)如果在 BeanFactory 中存在多个实例,则匹配失败;
(2)如果在 BeanFactory 中仅仅存在一个实例,则匹配成功
在这里插入图片描述

2. mybatis的xml文件配置

这种方式是查资料找到的,未做测试,

(1)、spring-dao.xml增加以下红色部分:

<bean name="自己的" id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
   <property name="dataSource" ref="mysqlDB"/>
   <property name="mapperLocations">
      <array>
      	  <!-- 这里是自己项目的xml文件路径 -->
         <value>classpath*:/mappings/**/*.xml</value>
         <!-- 这里是flowavle的xml文件路径 -->
         <value>classpath:/META-INF/modeler-mybatis-mappings/*.xml</value>
      </array>
   </property>
   <property name="configLocation" value="classpath:/config/mybatis-config.xml"/>
</bean>

(2)、mybatis-config.xml增加如下部分:

<properties resource="flowable.properties">
   <property name="blobType" value="BLOB"></property>
   <property name="boolValue" value="TRUE"></property>
   <property name="prefix" value=""></property>
</properties>

(3)、flowable.properties增加以下部分:

blobType=BLOB
boolValue=TRUE
prefix=

3. 手动SqlSessionFactory

由于项目的多数据源,所以需要手动去生成SqlSessionFactory

	@Bean
	@Primary
	public SqlSessionFactory sqlSessionFactoryCore() throws Exception {
		MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
		sqlSessionFactoryBean.setDataSource(shardingSphereDataSourceCore());
		//这里是自己项目的xml文件路径
		Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath:com/domain/core/**/*Mapper.xml");
		Resource[] resources2 = new PathMatchingResourcePatternResolver().getResources("classpath:com/domain/flowable/**/*Mapper.xml");
		//这里是jar包的xml文件路径
		Resource[] resources3 = new PathMatchingResourcePatternResolver().getResources("classpath:/META-INF/modeler-mybatis-mappings/*.xml");
		int length1 = resources.length;
		int length2 = resources2.length;
		int length3 = resources3.length;
		Resource[] newResources = new Resource[length1 + length2 + length3];
		List<Resource> newResourceList = new ArrayList<>();
		List<Resource> resourcesList1 = Arrays.asList(resources);
		List<Resource> resourcesList2 = Arrays.asList(resources2);
		List<Resource> resourcesList3 = Arrays.asList(resources3);
		newResourceList.addAll(resourcesList3);
		newResourceList.addAll(resourcesList1);
		newResourceList.addAll(resourcesList2);
		if(CollectionUtil.isNotEmpty(newResourceList)){
			for (int i = 0; i < newResourceList.size(); i++) {
				newResources[i] = newResourceList.get(i);
			}
		}
		sqlSessionFactoryBean.setMapperLocations(newResources);
		//插件,看自己需求,不用的可以注释
		sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageInterceptorCem, mybatisPlusInterceptorCem});
		GlobalConfig globalConfig = new GlobalConfig();
		DbConfig dbConfig = new DbConfig();
		dbConfig.setIdType(IdType.ASSIGN_UUID);
		globalConfig.setDbConfig(dbConfig);
		globalConfig.setMetaObjectHandler(customMetaObjectHandler);
		//数据库一些配置
		sqlSessionFactoryBean.setGlobalConfig(globalConfig);
		//这里去做参数处理,MybatisConfiguration是继承mybatis的Configuration
		MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
		mybatisConfiguration.setMapUnderscoreToCamelCase(false);
		//设置参数
		Properties properties = new Properties();
		properties.setProperty("boolValue", "true");
		properties.setProperty("blobType", "BLOB");
		properties.setProperty("prefix", "");
		mybatisConfiguration.setVariables(properties);
        sqlSessionFactoryBean.setConfiguration(mybatisConfiguration);
        //返回SqlSessionFactory
		return sqlSessionFactoryBean.getObject();
	}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值