mybatis+springboot+flowable6.4.0遇到的问题

1 篇文章 0 订阅
1 篇文章 0 订阅
在整合Flowable6.4.0与MyBatis+SpringBoot时遇到`org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)`错误。问题源于`@ConditionalOnMissingBean`导致MyBatis配置被Flowable覆盖。解决方案包括排除Flowable的SqlSession注入,增加Flowable属性配置,并在特定配置中注入Bean,以解决表找不到等问题。
摘要由CSDN通过智能技术生成

前面一大堆都是记录问题过程,爱看不看。解决办法再最后。

问题:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

写错对应关系 namespace等骚操作造成的就不说了。动动脑子。下面主要说冲突导致的这个问题。
源码查看:
1 报错位置

 MappedStatement ms = resolveMappedStatement(mapperInterface, methodName, declaringClass,
          configuration);
      if (ms == null) {
        if (method.getAnnotation(Flush.class) != null) {
          name = null;
          type = SqlCommandType.FLUSH;
        } else {
          throw new BindingException("Invalid bound statement (not found): "
              + mapperInterface.getName() + "." + methodName);
        }
        ...

2 ms为啥为空 因为 mappedStatements里没有(MapperLocations配置没生效)

private MappedStatement resolveMappedStatement(Class<?> mapperInterface, String methodName,
        Class<?> declaringClass, Configuration configuration) {
      String statementId = mapperInterface.getName() + "." + methodName;
      if (configuration.hasStatement(statementId)) {
        return configuration.getMappedStatement(statementId);
      } else if (mapperInterface.equals(declaringClass)) {
        return null;
      }
  public boolean hasStatement(String statementName) {
    return hasStatement(statementName, true);
  }

  public boolean hasStatement(String statementName, boolean validateIncompleteStatements) {
    if (validateIncompleteStatements) {
      buildAllStatements();
    }
    return mappedStatements.containsKey(statementName);
  }

3 真正原因! @ConditionalOnMissingBean !!!!:如果容器中没有,就注入,如果有就不注入.mybatis的sqlsession被flowable的覆盖了

mybatis的:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration里
@Bean
   @ConditionalOnMissingBean
   public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
  	 ...
   factory.setMapperLocations(this.properties.resolveMapperLocations());
  	...
   }
   
flowable的:org.flowable.ui.modeler.conf.DatabaseConfiguration里
@Bean
   public SqlSessionFactory sqlSessionFactory(DataSource dataSource) {
       SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
       sqlSessionFactoryBean.setDataSource(dataSource);
       String databaseType = this.initDatabaseType(dataSource);
       if (databaseType == null) {
           throw new FlowableException("couldn't deduct database type");
       } else {
           try {
               Properties properties = new Properties();
               properties.put("prefix", this.modelerAppProperties.getDataSourcePrefix());
               properties.put("blobType", "BLOB");
               properties.put("boolValue", "TRUE");
               properties.load(this.getClass().getClassLoader().getResourceAsStream("org/flowable/db/properties/" + databaseType + ".properties"));
               sqlSessionFactoryBean.setConfigurationProperties(properties);
               sqlSessionFactoryBean.setMapperLocations(ResourcePatternUtils.getResourcePatternResolver(this.resourceLoader).getResources("classpath:/META-INF/modeler-mybatis-mappings/*.xml"));
               sqlSessionFactoryBean.afterPropertiesSet();
               return sqlSessionFactoryBean.getObject();
           } catch (Exception var5) {
               throw new FlowableException("Could not create sqlSessionFactory", var5);
           }
       }
   }

4 很明显,mybatis的配置被覆盖了。吐槽一下flowable-ui的源码:臭虫,都是臭虫!

解决办法:就是兼顾 flowable和mybatis的配置.

1 第一步 排除flowable的sqlsession注入:

在@ComponentScan里加入这样的话。
@Filter(type = FilterType.ASSIGNABLE_TYPE, classes = DatabaseConfiguration.class)

2 第二步 增加flowable的属性配置等。application.properties里添加如下配置。加modeler-mybatis-mapping那个

mybatis.mapperLocations=classpath*:mapper/*/*.xml,classpath:/META-INF/modeler-mybatis-mappings/*.xml
#这里就是配个空。或者配置数据库用户名 username也行,不要瞎改哈(这个是查询前缀-flowable)
mybatis.configuration-properties.prefix =
mybatis.configuration-properties.blobType = BLOB
mybatis.configuration-properties.boolValue = TRUE

3 第三步,做到这直接启动项目可能会报 act_de_model表找不到等错误。再一个@Configuration配置里加入以下bean的注入

@Bean
  public Liquibase liquibase(DataSource dataSource) {
      Liquibase liquibase = null;

      Liquibase var5;
      try {
          DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
          Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
          database.setDatabaseChangeLogTableName("ACT_DE_" + database.getDatabaseChangeLogTableName());
          database.setDatabaseChangeLogLockTableName("ACT_DE_" + database.getDatabaseChangeLogLockTableName());
          liquibase = new Liquibase("META-INF/liquibase/flowable-modeler-app-db-changelog.xml", new ClassLoaderResourceAccessor(), database);
          liquibase.update("flowable");
          var5 = liquibase;
      } catch (Exception var9) {
          throw new InternalServerErrorException("Error creating liquibase database", var9);
      } finally {
      }
      return var5;
  }

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ToBeYourBaBa

你支持下,我才有兴趣更新

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值