springboot整合mybatis遇到無法掃描MaperScan包的問題


1.啟動類加上@MaperScan注解后,一直報錯如下:

Error creating bean with name 'platUserMapper' defined in file [D:\workspace\eclipse_data\vivo\target\classes\test\interf\domain\mapper\PlatUserMapper.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后重新啟動,可正常啟動。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM