错误信息
Exception in thread "main" 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(java.sql.Connection)
### 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(java.sql.Connection)
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:100)
其实仔细看报错提示,追到源码里看一下就知道原因了,因为用了比较新或者是最新的MyBatis jar包,而我的拦截器代码又是比较老的写法。在MyBatis新的jar包中,StatementHandler中的prepare方法有两个参数,如下:Statement prepare(Connection connection, Integer transactionTimeout),而我的拦截器代码里面却只有一个参数,所以就导致获取不到。解决方法便出来了,应该在分页拦截器的规则里面再追加一个Integer.class参数。如下:
@Intercepts({@Signature(type=StatementHandler.class,method="prepare",args={Connection.class, Integer.class })})