当前位置:主页 > 软件编程 > JAVA代码 >

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

时间:2021-05-09 07:46:42 | 栏目:JAVA代码 | 点击:

网上说是使用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>

您可能感兴趣的文章:

相关文章