(1) Problem Description
This week at work, the company’s project using mybatis and pagehelper for paging queries, start the project, query data actually reported an error, the error reported as follows.
Exception in thread “main” org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.Executor named query. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.Executor.query(org.apache.ibatis.mapping.MappedStatement, java.lang.Object, org.apache.ibatis.session.RowBounds, org.apache.ibatis.session.ResultHandler, org.apache.ibatis.cache.CacheKey, org.apache.ibatis.mapping.BoundSql)
Exception in thread "main" org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.Executor named query. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.Executor.query(org.apache.ibatis.mapping.MappedStatement, java.lang.Object, org.apache.ibatis.session.RowBounds, org.apache.ibatis.session.ResultHandler, org.apache.ibatis.cache.CacheKey, org.apache.ibatis.mapping.BoundSql)
at org.apache.ibatis.plugin.Plugin.getSignatureMap(Plugin.java:63)
at org.apache.ibatis.plugin.Plugin.wrap(Plugin.java:26)
at com.github.pagehelper.PageInterceptor.plugin(PageInterceptor.java:151)
at org.apache.ibatis.plugin.InterceptorChain.pluginAll(InterceptorChain.java:12)
at org.apache.ibatis.session.Configuration.newExecutor(Configuration.java:289)
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:78)
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:32)
Caused by: java.lang.NoSuchMethodException: org.apache.ibatis.executor.Executor.query(org.apache.ibatis.mapping.MappedStatement, java.lang.Object, org.apache.ibatis.session.RowBounds, org.apache.ibatis.session.ResultHandler, org.apache.ibatis.cache.CacheKey, org.apache.ibatis.mapping.BoundSql)
at java.lang.Class.getMethod(Class.java:1786)
at org.apache.ibatis.plugin.Plugin.getSignatureMap(Plugin.java:60)
After thinking for a long time, I didn’t understand what went wrong. Then I inadvertently checked the underlying source code of PageHelper and found that there were errors, as shown below:
Then enter the query () method and jump to the source code of the mybatis framework. It is found that the method in the mybatis framework has only four parameters, while the query () method with six parameters is used in the PageHelper, resulting in an error.
The reason for the problem is that there must be a mismatch between the versions of the mybatis framework and the page helper. I checked that the mybatis version used in the company’s project is 3.0.4 and the PageHelper version is 5.0.0. The solution is simple. Replace the corresponding framework version.
(2) Solution
There are two ways to solve this problem:
Change the version corresponding to mybatis and PageHelper (this is the simplest way). Instead of using the PageHelper plug-in, customize the mybatis paging plug-in
1. Method 1: replace mybatis version
I checked the page helper dependency repository and found that the page helper supports mybatis version 3.2.6 at least.
2. Custom mybatis paging plug-in
The version of mybatis 3.0.4 used by our company. At that time, the technical manager specially told me that if it is a problem with the dependent version, the dependency of PageHelper can be replaced at will, but the dependent version of mybatis cannot be replaced. Ah, I think it’s not just a custom mybatis paging plug-in… I can’t help it. I can only view some articles about custom paging plug-ins, and then write one myself. If necessary, you can check the article [mybatis implementation of custom paging plug-in].
Read More:
- mybatis-plus calls its own selectById method and reports an error: org.apache.ibatis.binding.BindingException:
- [Solved] Mybatis crud insert error: org.apache.ibatis.binding.BindingException: Mapper method ‘com.liang.dao.UserMapper.addUser…
- SpringBoot uses MyBatis error: Error invoking SqlProvider method (tk.mybatis.mapper.provider.base.BaseInsertProvider.dynamicSQL)
- [Solved] Mybatis Error: Resources.getResourceAsStream(resource) cannot find the method
- [Solved] Mybatis:Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance.
- [Solved] Mybatis Error: Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.
- [Solved] Mybatis Error: CannotFindDataSourceException: dynamic-datasource can not find primary datasource
- Mybatis-plus calls its own method error: Invalid bound statement
- Sentinel could not find the urlblockhandler interface solution
- Solution of Hibernate paging report only entering result set and not supporting requested operation
- How to Solve org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) Error
- [Solved] ibatis.builder.BuilderException: Error parsing Mapper XML: Could not resolve type alias ‘XXX‘
- Aspecj cannot intercept method annotations on an interface
- MyBatis: Mapped Statements collection does not contain value for xxx
- [Solved] mybatis plus Error: Invalid bound statement (not found)
- [Solved] java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession
- [Solved] webpack.config.js configuration encountered Error: Cannot find module’@babel/core’&&Cannot find module’@babel/plugin-transform-react-jsx’
- Java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; error resolution
- [Solved] Mybatis-plus Error: mybatisplus-Invalid bound statement (not found): com.integration.dao.ApiDao.getList
- How to Solve Error: IncompleteElementException: Could not find result map…