spring 配置c3p0出的问题!

今天在学习Spring的时候用到了c3p0的链接池链接数据库,所以导入了c3p0-0.9.5.1.jar包和mysql-connector-java-5.1.7-bin.jar的包,然后编写了bean文件和Main类,如下图


然后就报了如下错误。

异常:警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [bean-dataSource.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mchange.v2.c3p0.ComboPooledDataSource]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: com/mchange/v2/ser/Indirector 
查了好多资料,最后说是缺少mchange-commons-java-0.2.3.4.jar包,然后去下载导入以后又报了另外一个错,然后感觉不对,仔细看了一下下载的c3p0的包

结果是mchange-commons-java-0.2.10.jar版本的包才可以使用,这个包是和c3p0的jar包一起下载的,导入以后就运行成功了。

总结:包之间的版本号一定要相互统一。


发布了49 篇原创文章 · 获赞 17 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/unhejing/article/details/79145445