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

 更新时间:2025年11月14日 09:32:55   作者:ToBeYourBaBa  
文章主要介绍了MyBatis和Flowable在Spring Boot项目中的冲突问题,以及如何通过排除Flowable的SQLSession注入、增加Flowable属性配置和处理数据库表错误来解决这个问题

问题

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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • spring定时器@Scheduled异步调用方式

    spring定时器@Scheduled异步调用方式

    在Spring Boot中,@Schedule默认使用单线程执行定时任务,多个定时器会按顺序执行,为实现异步执行,可以通过自定义线程池或实现SchedulingConfigurer接口,使用自定义线程池可以保证多个定时器并发执行
    2024-11-11
  • JAVA调用JavaScript方法举例详解

    JAVA调用JavaScript方法举例详解

    之前在一次机缘巧合的情况下,需要时用JAVA执行js方法,查阅了一些文档,找到了相关解决方法,这里和大家分享一下,下面这篇文章主要给大家介绍了关于JAVA调用JavaScript方法的相关资料,需要的朋友可以参考下
    2023-10-10
  • eclipse修改jvm参数调优方法(2种)

    eclipse修改jvm参数调优方法(2种)

    本篇文章主要介绍了eclipse修改jvm参数调优方法(2种),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-02-02
  • 浅析Java 数据结构常用接口与类

    浅析Java 数据结构常用接口与类

    本篇文章主要介绍了Java中的数据结构,Java工具包提供了强大的数据结构。需要的朋友可以参考下
    2017-04-04
  • Spring Boot 集成 Sharding-JDBC + Mybatis-Plus 实现分库分表功能

    Spring Boot 集成 Sharding-JDBC + Mybatis-Plus 实现分库分表功能

    这篇文章主要介绍了Spring Boot 集成 Sharding-JDBC + Mybatis-Plus 实现分库分表功能,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-08-08
  • Spring boot webService使用方法解析

    Spring boot webService使用方法解析

    这篇文章主要介绍了Spring boot webService使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-09-09
  • Spring BOOT AOP基础应用教程

    Spring BOOT AOP基础应用教程

    这篇文章主要介绍了Spring BOOT AOP的使用,文章从相关问题展开全文内容详情,具有一定的参考价值,需要的小伙伴可以参考一下
    2022-07-07
  • 关于dubbo的超时处理及重试原则

    关于dubbo的超时处理及重试原则

    这篇文章主要介绍了关于dubbo的超时处理及重试原则,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-08-08
  • Java IO流之StringWriter和StringReader用法分析

    Java IO流之StringWriter和StringReader用法分析

    这篇文章主要介绍了Java IO流之StringWriter和StringReader用法分析,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-12-12
  • Java获取项目路径方式System.getProperty(“user.dir“)

    Java获取项目路径方式System.getProperty(“user.dir“)

    这篇文章主要介绍了Java获取项目路径方式System.getProperty(“user.dir“),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-12-12

最新评论