• 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后重新启动,可正常启动。

  • 相关阅读:
    月薪 30K Java 程序员,需要掌握哪些技术?
    docker-compose安装mongodb
    docker-compose安装apollo服务
    docker-compose安装mysql和redis
    编程总结1:打印沙漏
    秋季学习总结
    对我人生影响最大的三位老师
    自我介绍
    秋季学习总结
    人生路上对我影响最大的三位老师
  • 原文地址:https://www.cnblogs.com/wwmiert/p/9838221.html
Copyright © 2020-2023  润新知