2016-07-25 6 views
0

Я использовал Mybatis для создания Interceptor, но когда я запустил его, консоль отобразила, что в классе StatementHandler нет «подготовленного» именованного метода. Есть что-то еще, что мне нужно сделать?Не удалось найти метод на интерфейсе org.apache.ibatis.executor.statement.StatementHandler named 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) 
+0

Какие методы документации говорят, есть? –

+0

Метод под названием «подготовить» не может быть найден в org.apache.ibatis.executor.statement.StatementHandler при выполнении программы. но есть один. – Frank

+0

Вы уверены, что используемые вами типы параметров верны? Документация, которую я нашел, не говорит, что метод имеет параметр Integer –

ответ

0

Определение вашего перехватчика использует неправильный Connection класс. Вы используете 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) 
+0

Вы правы, он работает! большое спасибо – Frank

 Смежные вопросы

  • Нет связанных вопросов^_^