报如下异常,说明spring和mybais的包整合不匹配
Exception in thread "main" java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFactory.newTransaction(Ljava/sql/Connection;)Lorg/apache/ibatis/transaction/Transaction
Exception in thread "main" java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransactionFactory.newTransaction(Ljava/sql/Connection;)Lorg/apache/ibatis/transaction/Transaction;
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromConnection(DefaultSqlSessionFactory.java:98)
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:71)
at org.mybatis.spring.SqlSessionUtils.getSqlSession(SqlSessionUtils.java:135)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:345)
at $Proxy4.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:155)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at $Proxy5.selectUserByID(Unknown Source)
at com.jy.test.MybatisSprintTest.main(MybatisSprintTest.Java:27)
原创,必须是原创,就这个问题差点把我搞崩溃,我就一句话,mybatis和spring整合的时候jar包版本要匹配。
出现问题jar包版本:
mybatis-32.3.jar mybatis-spring-1.0.3-SNAPSHOT.jar
换成如下版本成功解决问题,不再报异常
mybatis-3.0.6.jar mybatis-spring-1.0.3-SNAPSHOT.jar