• Mybatis || Mybatis-Plus中configuration和configLocation无法同时使用记录


    Mybatis || Mybatis-Plus中configuration和configLocation无法同时使用记录

    1. 当在SpringBoot项目中配置的yml中对于mybatis || mp的参数同时配置了configuration和configLocation的情况下会导致的问题如下

    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.IllegalStateException: Property 'configuration' and 'configLocation' can not specified with together
    
    • 1

    解析原因是因为框架就是不允许这个样子, 因为mp是mybatis的加强, 所以也会出现同样的问题

    2. 具体代码如下

    • mybatis的代码是SqlSessionFactoryBean类中的

      @Override
      public void afterPropertiesSet() throws Exception {
          notNull(dataSource, "Property 'dataSource' is required");
          notNull(sqlSessionFactoryBuilder, "Property 'sqlSessionFactoryBuilder' is required");
          state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null),
                "Property 'configuration' and 'configLocation' can not specified with together");
      
          this.sqlSessionFactory = buildSqlSessionFactory();
      }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
    • mybatis的代码是MybatisSqlSessionFactoryBean类中

      @Override
      public void afterPropertiesSet() throws Exception {
          notNull(dataSource, "Property 'dataSource' is required");
          state((configuration == null && configLocation == null) || !(configuration != null && configLocation != null),
                "Property 'configuration' and 'configLocation' can not specified with together");
          //TODO 清理掉资源  建议不要保留这个玩意了
          SqlRunner.DEFAULT.close();
          this.sqlSessionFactory = buildSqlSessionFactory();
      }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9

    具体还是使用yml优雅一点,可能没人会两个都用

  • 相关阅读:
    FlinkSQL-- sql-client及源码解析 -- flink-1.13.6
    vue 和 后端交互
    基于python和django旅游管理系统
    Swift的基本数据类型
    【前端】在Vue页面中引入其它vue页面 数据传输 相互调用方法等
    Rhino网格如何转化成曲面?
    python详解(4)——异常、类、作用域and自定义模块
    【数据结构】堆的拓展延伸 —— 堆排序 和 TopK问题
    Java Comparator 自定义复杂排序
    java基于微信小程序的旅游网站 uniapp 小程序
  • 原文地址:https://blog.csdn.net/weixin_43194885/article/details/127720826