Tag Archives: Trampled pit

Mybatis Error: Invalid bound statement (not found)

When starting the project today, the spring boot reported an error.

This error is reported because the mapper file has not been scanned.

Why didn’t you scan it?

Cause analysis

    1. incorrect namespace method undefined: the method in mapper.xml is not defined in the Java class. The return value is incorrect: the return value of the method in the Java class is different from the return value in the XML file (resultmap or resulttype). The configuration path is incorrect: is the configuration path of the mapper file correct

The error reason of my project is the fourth: the configuration path of mapper file is incorrect

The path I configured in the project is: all XML files under the mapper folder and its subfolders.

However, my project doesn’t have a mapper folder at all

Just looking at this folder, I don’t know whether it is a primary directory or a hierarchical directory.

When I created a new folder, I entered it in one breath

Although the name of the folder is written correctly, the name of the folder is mapper.subnet

In this case, there is no mapper folder at all, so it will not be able to match.

Mybatis property loading order [How to Solve]

Mybatis property loading order

⚠️ Note: if a property is configured in more than one place, mybatis will be loaded in the following order:

First read the properties specified in the properties element body. Then read the config.properties file under the classpath according to the resource attribute in the properties element, or read the property file according to the path specified by the URL attribute, and overwrite the previously read property with the same name. Finally, read the property passed as a method parameter and overwrite the previously read property with the same name.

Sort by priority: method parameters > Profile > Properties element properties