How to solve the error when running mybatis using junit when testing

Error result after running unit test:

Error 1: The document root element "configuration" must match the DOCTYPE root "null"

Reason: The mybatis configuration core file lacks some xml configuration file information or the configuration file is written incorrectly.

Solution: We need to ensure that the content of the marked place in the configuration must be the same. If it is different, it will cause the program to run incorrectly. If the hook code is missing, please complete it. If the code is missing, the element attributes will not be found. As shown below

Source code of error 1 solution:

<?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">

Error 2: The document root element "mapper" must match the DOCTYPE root "null"

Reason: The configuration file in the mapper interface is incomplete or the configuration file is incorrectly written.

Solution to error 2: We must ensure that the xml configuration file contains the mapper interface, not the configuration interface, or there is no configuration information for the interface, as shown in the figure below

Source code of error 2 solution:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

Guess you like

Origin blog.csdn.net/weixin_55897008/article/details/129396544