IDEA Mybatis 找不到映射器xml文件

  用IDEA新建了一个测试MyBatis工程,工程目录如下

  IDEA Mybatis 找不到映射器xml文件

  其中config是MyBatis的配置文件,内容如下

  

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"></transactionManager>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis"/>
<property name="username" value="root"/>
<property name="password" value="19871111"/>
</dataSource>
</environment>
</environments> <mappers>
<mapper resource="com/shao/mapping/userMapper.xml"/>
</mappers>
</configuration>

  编译时提示错误  Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/shao/mapping/userMapper.xml

  即找不到userMapper.xml这个Mapper文件,仔细查看了目录设置,并没有错误,在网上找了半天,终于发现原因:

   idea不会编译src的java目录的xml文件  

  所以解决思路就是:将IDEA maven项目中src源代码下的xml等资源文件编译进classes文件夹

  具体操作方法就是:配置maven的pom文件配置,在<build>节点下添加<resources>代码:

  

    <build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>
上一篇:java课后作业6


下一篇:各种字符编码方式详解及由来(ANSI,UNICODE,UTF-8,GB2312,GBK)