java.lang.IllegalAccessError: org.apache.commons.dbcp.DelegatingPreparedStatement.isClosed()Z
做spring和mybaits整合时出现的错误,让这个问题困扰了一早上,通过查资料终于把这个问题解决了
具体问题描述:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 java.lang.IllegalAccessError: org.apache.commons.dbcp.DelegatingPreparedStatement.isClosed()Z 2 3 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 4 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 5 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 6 at java.lang.reflect.Method.invoke(Method.java:498) 7 at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:78) 8 at com.sun.proxy.$Proxy14.isClosed(Unknown Source) 9 at org.apache.ibatis.executor.BaseExecutor.closeStatement(BaseExecutor.java:285) 10 at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:65) 11 at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) 12 at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) 13 at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) 14 at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) 15 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) 16 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) 17 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) 18 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 19 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 20 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 21 at java.lang.reflect.Method.invoke(Method.java:498) 22 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) 23 at com.sun.proxy.$Proxy11.selectOne(Unknown Source) 24 at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) 25 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:83) 26 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) 27 at com.sun.proxy.$Proxy12.queryUserById(Unknown Source) 28 at com.shen.test.testMybaits.test1(testMybaits.java:16) 29 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 30 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 31 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 32 at java.lang.reflect.Method.invoke(Method.java:498) 33 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 34 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 35 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 36 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 37 at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 38 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 39 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 40 at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 41 at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 42 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 43 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 44 at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 45 at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 46 at org.junit.runner.JUnitCore.run(JUnitCore.java:160) 47 at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 48 at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) 49 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) 50 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
问题的大概意思是:
简单来说就是mybatis出现了问题,而问题关键在于mybatis.jar包版本不符,试着用老一点的版本就可以运行了。对于这种问题得多看看jar包的官方文档
解决的方法:
把mybatis的jar的版本将低点