zoukankan      html  css  js  c++  java
  • springboot整合mybatis遇到无法扫描MaperScan包的问题

    1.启动类加上@MaperScan注解后,一直报错如下:

    Error creating bean with name 'platUserMapper' defined in file [D:workspaceeclipse_datavivo argetclasses estinterfdomainmapperPlatUserMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    原因是pom.xml没有引入如下依赖,因为从SqlSessionDaoSupport 这个类的源码中可以看出,原因是mybatis-spring-1.2.0中取消了自动注入SqlSessionFactory 和 SqlSessionTemplate

    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.0</version>
    </dependency>

    2.引入如上依赖包后,再次报错,报错如下:

    Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.apache.ibatis.session.Configuration.setVfsImpl(Ljava/lang/Class;)V

    查看源码发现该类中不存在set方法 ,升级mybatis版本如下:

    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.4</version>
    </dependency>

    仍然报错:Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoSuchMethodError: org.mybatis.spring.SqlSessionFactoryBean.setVfs(Ljava/lang/Class;)V

    升级mybatis-spring:

    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.3.1</version>
    </dependency>

    更新pom后重新启动,可正常启动。

  • 相关阅读:
    C语言文法修改
    C语言文法
    词法分析程序实验报告
    php设置http响应头和数据库查询字符集编码
    提交form前先使用JS进行验证
    iOS 移动端清除按钮的默认样式
    innerText与textContent的异同
    JS事件应用
    docker redis安装
    cmder的快捷键
  • 原文地址:https://www.cnblogs.com/wwmiert/p/9838221.html
Copyright © 2011-2022 走看看