springboot与mybatis整合时会发现mapper文件必须放在resource下,这样对于一些人很不习惯。这样我们说一下解决办法。以及使用中的一个小坑:在Intellij IDEA中无法识别在src文件夹下的xml。
在Eclipse中:
#mybatis配置文件所在路径
mybatis.config-location:classpath:mybatis-config.xml
#所有的mapper映射文件
mybatis.mapper-locations:classpath*:com/springboot/mapper/*.xml
在IDEA中:
在pom.xml 加入如下配置即可(跳过测试打包:clean package -Dmaven.test.skip=true
<build>
<resources>
<!-- 如果不加,那么打包的时候mapper文件不会被加载进来 -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
Tips:如果项目启动不起来,报**“Unable to start embedded container”**,则删除掉标签,启动后再加上标签重启,即可解决。神之操作,别问不懂。 —。–