Tag Archives: the binding mapper cannot be found Error

[Solved] Mybatis: the binding mapper cannot be found Error: Org.apache.ibatis.binding.bindingexception: invalid bound statement (not found)

Cause

By default, mybatis will go to the directory where the interface file is located to find the XML file. When the XML file and the interface file directory are not in the same directory, an error will be reported:

org.apache.ibatis.builder.IncompleteElementException: Could not find a parent resultmap with id 'top.testops.mall.mbg.mapper.CheckGroupMapper'
	at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:188) ~[mybatis-3.5.7.jar:3.5.7]
	at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:47) ~[mybatis-3.5.7.jar:3.5.7]
	at org.apache.ibatis.session.Configuration.parsePendingResultMaps(Configuration.java:909) ~[mybatis-3.5.7.jar:3.5.7]
	at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:873) ~[mybatis-3.5.7.jar:3.5.7]
	at com.baomidou.mybatisplus.core.MybatisConfiguration.hasStatement(MybatisConfiguration.java:303) ~[mybatis-plus-core-3.4.3.4.jar:3.4.3.4]
	at org.apache.ibatis.session.Configuration.hasStatement(Configuration.java:853) ~[mybatis-3.5.7.jar:3.5.7]
	at org.apache.ibatis.binding.MapperMethod$SqlCommand.resolveMappedStatement(MapperMethod.java:257) ~[mybatis-3.5.7.jar:3.5.7]

Solution

Method 1:

Put the interface file in the same directory as the XML file

Method 2

Configure mapper locations in the application.yml file, that is:

mybatis-plus:
  mapper-locations: classpath:top/testops/**/*.xml

Note 1:

The configuration here is not classpath: path/to/mappers/*.XML , but classpath: COM/my/package/persistence/*.XML . That is, it is not the path of the XML file, but the directory corresponding to the package name (e.g. Src/main/Java/example/mapper/.XML), but the package name in Java (e.g. top/testops/mapper/.XML, and the package name of XML is: top.testops.mapper)

Note 2:

When the mapper is not placed in the resources directory, the XML file will not be compiled into the target folder. Configuration needs to be added in the POM.XML file:

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