新建了maven工程,集成了Spring及Mybatis,进行CRUD时出错,总结如下:
1.NoClassDefFoundError: org/apache/ibatis/session/SqlSession
这是因为缺少了ibatis-core依赖,在pom.xml中加入即可。
<!-- https://mvnrepository.com/artifact/org.apache.ibatis/ibatis-core -->
<dependency>
<groupId>org.apache.ibatis</groupId>
<artifactId>ibatis-core</artifactId>
<version>3.0</version>
</dependency>
2.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource
这是因为C3P0版本太低,要换成0.9.5以上。
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
3.NoClassDefFoundError: org/apache/ibatis/mapping/DatabaseIdProvider
这是mybatis和mybatis-spring不兼容导致的。换成兼容的即可。
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>