项目访问接口报错:

排查发现mapper文件没有编译进target,mapper目录下只有class文件没有mapper.xml:

解决方法:在build标签中使用<resources>标签指向mapper.xml文件位置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
重新编译,问题解决。不过仍然存在的疑问是之前在application.properties文件中已经配置了属性mybatis.mapper-locations来指向mapper.xml的文件目录,不知道为什么还要再pom中添加resource标签
本文介绍了一种常见问题的解决方案,即在Spring Boot项目中,Mapper XML文件未能编译到target目录的问题。通过在pom.xml的build标签中添加资源配置,指向Mapper XML文件的位置,确保它们被正确编译。尽管application.properties已配置mybatis.mapper-locations,但此额外步骤仍为必要。
1万+

被折叠的 条评论
为什么被折叠?



