无法在名为 prepare 的接口 org.apache.ibatis.executor.statement.StatementHandler 上找到方法
Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare
我使用 Mybatis 创建了一个拦截器,但是当我 运行 它时,控制台显示在 StatementHandler class 中没有 "prepare" 命名方法。我还需要做什么吗?
这是注释:
@Intercepts({ @Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class, Integer.class }) })
org.apache.ibatis.exceptions.PersistenceException:
### Error opening session. Cause: org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
### Cause: org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47)
com.fj.db.DBAccess.getSqlSession(DBAccess.java:30)
com.fj.dao.MessageDao.count(MessageDao.java:121)
com.fj.service.QueryService.queryMessageList(QueryService.java:34)
com.fj.servlet.ListServlet.doGet(ListServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
org.apache.ibatis.plugin.Plugin.getSignatureMap(Plugin.java:87)
org.apache.ibatis.plugin.Plugin.wrap(Plugin.java:44)
com.fj.interceptor.PageInterceptor.plugin(PageInterceptor.java:121)
org.apache.ibatis.plugin.InterceptorChain.pluginAll(InterceptorChain.java:31)
org.apache.ibatis.session.Configuration.newExecutor(Configuration.java:553)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:96)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47)
com.fj.db.DBAccess.getSqlSession(DBAccess.java:30)
com.fj.dao.MessageDao.count(MessageDao.java:121)
com.fj.service.QueryService.queryMessageList(QueryService.java:34)
com.fj.servlet.ListServlet.doGet(ListServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
java.lang.Class.getMethod(Class.java:1786)
org.apache.ibatis.plugin.Plugin.getSignatureMap(Plugin.java:84)
org.apache.ibatis.plugin.Plugin.wrap(Plugin.java:44)
com.fj.interceptor.PageInterceptor.plugin(PageInterceptor.java:121)
org.apache.ibatis.plugin.InterceptorChain.pluginAll(InterceptorChain.java:31)
org.apache.ibatis.session.Configuration.newExecutor(Configuration.java:553)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:96) org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47)
com.fj.db.DBAccess.getSqlSession(DBAccess.java:30)
com.fj.dao.MessageDao.count(MessageDao.java:121)
com.fj.service.QueryService.queryMessageList(QueryService.java:34)
com.fj.servlet.ListServlet.doGet(ListServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
你的拦截器定义使用错误Connection
class。您正在使用 com.mysql.jdbc.Connection
,但您应该使用 java.sql.Connection
。日志中的这一行为您提供了问题的确切原因
NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
StatementHandler
中的方法定义为
java.sql.Statement prepare(java.sql.Connection connection)
我使用 Mybatis 创建了一个拦截器,但是当我 运行 它时,控制台显示在 StatementHandler class 中没有 "prepare" 命名方法。我还需要做什么吗?
这是注释:
@Intercepts({ @Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class, Integer.class }) })
org.apache.ibatis.exceptions.PersistenceException:
### Error opening session. Cause: org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
### Cause: org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47)
com.fj.db.DBAccess.getSqlSession(DBAccess.java:30)
com.fj.dao.MessageDao.count(MessageDao.java:121)
com.fj.service.QueryService.queryMessageList(QueryService.java:34)
com.fj.servlet.ListServlet.doGet(ListServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.apache.ibatis.plugin.PluginException: Could not find method on interface org.apache.ibatis.executor.statement.StatementHandler named prepare. Cause: java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
org.apache.ibatis.plugin.Plugin.getSignatureMap(Plugin.java:87)
org.apache.ibatis.plugin.Plugin.wrap(Plugin.java:44)
com.fj.interceptor.PageInterceptor.plugin(PageInterceptor.java:121)
org.apache.ibatis.plugin.InterceptorChain.pluginAll(InterceptorChain.java:31)
org.apache.ibatis.session.Configuration.newExecutor(Configuration.java:553)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:96)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47)
com.fj.db.DBAccess.getSqlSession(DBAccess.java:30)
com.fj.dao.MessageDao.count(MessageDao.java:121)
com.fj.service.QueryService.queryMessageList(QueryService.java:34)
com.fj.servlet.ListServlet.doGet(ListServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
java.lang.Class.getMethod(Class.java:1786)
org.apache.ibatis.plugin.Plugin.getSignatureMap(Plugin.java:84)
org.apache.ibatis.plugin.Plugin.wrap(Plugin.java:44)
com.fj.interceptor.PageInterceptor.plugin(PageInterceptor.java:121)
org.apache.ibatis.plugin.InterceptorChain.pluginAll(InterceptorChain.java:31)
org.apache.ibatis.session.Configuration.newExecutor(Configuration.java:553)
org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:96) org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:47)
com.fj.db.DBAccess.getSqlSession(DBAccess.java:30)
com.fj.dao.MessageDao.count(MessageDao.java:121)
com.fj.service.QueryService.queryMessageList(QueryService.java:34)
com.fj.servlet.ListServlet.doGet(ListServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
你的拦截器定义使用错误Connection
class。您正在使用 com.mysql.jdbc.Connection
,但您应该使用 java.sql.Connection
。日志中的这一行为您提供了问题的确切原因
NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
StatementHandler
中的方法定义为
java.sql.Statement prepare(java.sql.Connection connection)