springboot-mybatis遇到的bug
1、[bug]Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’;
- 项目场景:
springboot整合mybatis时,将xxxMapper.xml 放在resources目录下,这时候运行报错如下:Unsatisfied dependency expressed through method ‘sqlSessionFactory’ parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dataSource’ defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration $Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method ‘dataSource’ threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
- 问题描述:
不能正确的启动项目
- 原因分析:
resources目录下资源被springboot拦截了
- 解决方案:
更改pom.xml文件,放行resource资源
在pom.xml <build/>标签里加入以下内容,问题解决
<!-- 添加资源 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- src/main/resources下的指定资源放行 -->
<includes>
<include>**/*.properties</include>
<include>**/*.yml</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>