当前位置: 代码网 > it编程>编程语言>Java > 解决mybatis+springboot+flowable6.4.0遇到的问题

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

2025年11月14日 Java 我要评论
问题org.apache.ibatis.binding.bindingexception: invalid bound statement (not found)写错对应关系 namespace等骚操

问题

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;
  }

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com