我使用Mybatis来创建一个Interceptor,但是当我运行它时,显示的控制台没有"准备" StatementHandler类中的命名方法。还有什么我需要做的吗?
这是注释:
@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)
答案 0 :(得分:0)
拦截器的定义使用了错误的override def receive = {
case msg =>
.... // do something
import akka.pattern.pipe
Future {
... // calculate response
}.pipeTo(sender())
}
类。您使用的是Connection
,但应使用com.mysql.jdbc.Connection
。日志中的这一行为您提供了问题的确切原因
java.sql.Connection
NoSuchMethodException: org.apache.ibatis.executor.statement.StatementHandler.prepare(com.mysql.jdbc.Connection, java.lang.Integer)
中的方法定义为
StatementHandler