java - mybatis 错误,找不到mapper?
伊谢尔伦
伊谢尔伦 2017-04-18 10:18:19
0
4
1003

这是mybatis-config.xml:

<?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"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url"
                          value="jdbc:mysql://localhost:3306/jupan_mail?useUnicode=true&amp;characterEncoding=UTF-8&amp;"/>
                <property name="username" value="root"/>
                <property name="password" value="password"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="com/salamander/backcal/mapping/MailChangeMapper.xml"/>
    </mappers>
</configuration>

这是项目结构:

单元测试报错:
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/salamander/backcal/dao/MailChangeMapper.xml

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(4)
迷茫

Find the solution (the reason is: idea will not compile the xml file in the java directory of src):
Add node in pom.xml:

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

Reference: http://www.cnblogs.com/canger...

刘奇

will not be in the java文件移至resources directory.

黄舟

com/salamander/backcal/dao/MailChangeMapper.xml
报错的路径是daoThis is included in the package.
But the configuration you posted is different from the error path.
Thought-provoking

迷茫

Configure a tag similar to <sanner></scanner> and give it a try.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!