SpringBoot Mybatis无法扫描xml SpringBoot整合Mybatis无法扫描xml文件的解决

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

SpringBoot Mybatis无法扫描xml SpringBoot整合Mybatis无法扫描xml文件的解决

linlinlinfeng   2021-01-28 我要评论

网上说是使用idea在SpringBoot整合Mybatis时候会扫描不到xml文件

1.将xml文件放在resources下

2.在application.properties中配置xml文件的扫面

补充知识:Springboot整合mybatis /*.xml路径URl does not exist问题

解决一:

在配置文件下 扫描不到 xml文件:

原来的文件:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/>
  <!-- 自动扫描mapping.xml文件 -->
  <property name="mapperLocations" value="classpath:com/qinkangdeid/mapping/*.xml"/>
</bean>

修改classpath 为 classpath*

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/>
  <!-- 自动扫描mapping.xml文件 -->
  <property name="mapperLocations" value="classpath*:com/qinkangdeid/mapping/*.xml"/>
</bean>

解决二:

war包里面缺少Mapper对应的xml文件,也就是没有把xml文件打包进去。解决办法是,在pom.xml文件中的build标签中添加如下代码,显示的强制将xml文件打到war包中:

  <resources>
    <resource>
      <directory>src/main/java</directory>
      <includes>
        <include>**/*.xml</include>
      </includes>
      <filtering>false</filtering>
    </resource>
  </resources>

以上这篇SpringBoot整合Mybatis无法扫描xml文件的解决就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们