springboot在打包的时候加载java目录中xml文件

最近在撸项目的时候发现一个问题,在使用mybatis-plus的时候,需要有一处地方用到sql语句,所以呢,我在java目录下写了xml文件
在这里插入图片描述
在xml文件中编写语句,运行后出现无法找到的结果,说明并没有打包进去了
遇到这种情况,有两种做法:
1、把xml文件放到resources中
2、pom文件进行如下配置

 <build>
        <!--项目打包时会讲java目录中的*.xml文件也进行打包-->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
    </build>

另外在application.yml文件中进行配置,当然,路径根据实际而定

mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:com/zeny/edu/eduservice/mapper/xml/*.xml

终于加载进来了
在这里插入图片描述

发布了26 篇原创文章 · 获赞 0 · 访问量 559

猜你喜欢

转载自blog.csdn.net/qq_36609994/article/details/104688054