目录
一、问题描述
1.使用Maven+SpringBoot+MyBatis测试,启动项目报错:Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’,也就是无法实例化,所有代码都没有问题
二、问题分析
1.检查mapper的namespace和查询返回值对应的类都存在

2.确保在SpringBoot配置文件中加载了mapper.xml文件

3.确保Maven的依赖关系-加载了mybatis-spring-boot

4.确保在启动类上加载了mapper.xml接口所在包@MapperScan(basePackages = {“mapper.xml接口所在包”})

5.上述检查都没有问题,最后才知道原来mapper.xml被Maven给拦截了,导致加载不上,从而无法实例化sqlSessionFactory
三、问题解决
1.在maven的pom.xml中放行mapper.xml,在Maven的build中加入以下配置,完整代码在最后
2.完整参考pom.xml
4.0.0
com.codecoord
JavaEEFrameReview
1.0-SNAPSHOT
war
JavaEEFrameReview Maven Webapp
http://www.example.com
UTF-8
1.8
1.8
org.springframework.boot
spring-boot-starter
2.0.5.RELEASE
org.springframework.boot
spring-boot-starter-jdbc
2.0.5.RELEASE
mysql
mysql-connector-java
5.1.42
com.oracle
ojdbc6
11.2.0.3
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
src/main/resources
/*.properties
/*.yml
/*.xml
false
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/222823.html原文链接:https://javaforall.net
