idea下 Maven创建 Spring+MyBatis项目 target下没有mapper.xml文件的解决方案

1、修改pom.xml,添加resources节点,将/src/main/java下的xml文件设置为资源文件

<build>
    <finalName>springWebTest</finalName>
    <resources>
      <resource>
        <directory>${basedir}/src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
    </resources>
  </build>

2、将mapper.xml放到resources文件夹下面,同时修改spring-mybatis.xml文件中 mapper.xml的路径

<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <!-- 自动扫描mapping.xml文件 -->
        <property name="mapperLocations" value="classpath:mapper/*Mapper.xml"></property>
    </bean>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容