Mybatis often has the following exception, which is generally an error in the xml mapping file. However, this prompt is not necessarily accurate, so that some information on the Internet says that this problem is very strange. The general solution to this error is explained below:
http://blog.csdn.net/softwarehe/article/details/8889206
The general reason is that the definitions of the Mapper interface and the xml file do not correspond. It is necessary to check whether the package name, namespace, function name, etc. can be matched. A more detailed comparison is required. Time not found error
Follow these steps one by one:
1: Check whether the package name where the xml file is located corresponds to the package name corresponding to the interface
2: Check if the namespace of the xml file corresponds to the package name of the xml file
3: Check whether the function name corresponds to
4: Remove the Chinese comment in the xml file
5: Feel free to add a space or blank line in the xml file and save
Generally speaking, you can eliminate the error here.
There are no problems with the above steps except step 5. Step 5 looks like such a weird solution, in fact, triggered the automatic compilation function of ide. Because the xml file is not always copied from the source directory to the compilation directory of the class file when compiling (MyEclipse often has this problem), sometimes the xml file in your source directory has been modified, and the directory where the class is located It's still old. So the really sure and effective way is to copy the correct xml file to the class output directory.
There are also cases where this error will occur, such as the configuration of xml mapping files that need to meet specific requirements
<Bean id = "sqlSessionFactory" class = "org.mybatis.spring.SqlSessionFactoryBean"
: P: dataSource-ref = "dataSource"
: P: configLocation = "classpath: mybatis-config.xml">
<Property name = "mapperLocations">
<list>
<value> classpath *: mapper / com / xxx / ** / * Mapper.xml </ value>
<value> classpath *: dao / com / xxx / ** / * Mapper.xml </ value>
</> </ List>
</ Property>
</ Bean>
As above, only the xml file at the end of Mapper will be scanned by Mybatis. If you forget this rule at this time, xml uses other names, such as xxxDao.xml. In this way, the configuration of xml will not be added to a map object of Mybatis storage configuration, and an error of Invalid bound statement will also appear. The solution is to rename the xml file.
————————————————
Copyright statement: This article is an original article of the CSDN blogger "Aha Program", following the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprint.
Original link: https://blog.csdn.net/yuexianchang/java/article/details/76369505
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.