c3p0的jar包已经加载正常,为何还报错说找不到com.mchange.v2.c3p0.ComboPooledDataSource

来源:5-2 配置去掉Hibernate的配置文件-Spring整合Hibernate

Night离

2017-02-08 16:22

c3p0的jar包已经加载正常,为何还报错说找不到com.mchange.v2.c3p0.ComboPooledDataSource

而且在类中import时时可以找到这个类的。但是在spring+Hibernate配置数据源的时候,启动Tomcat就报错啊!!!

 

急急急急急急!!!!!

错误信息如下:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mchange.v2.c3p0.ComboPooledDataSource] for bean with name 'datasource' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:959)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:683)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)

at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1548)

at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1512)

at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1748)

at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:333)

at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)

at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)

at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1370)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1542)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1552)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1520)

at java.lang.Thread.run(Thread.java:619)

Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1891)

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1734)

at org.springframework.util.ClassUtils.forName(ClassUtils.java:247)

at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)

at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)

at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)

... 23 more

2017-2-8 16:18:09 org.apache.catalina.core.StandardContext listenerStart

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.mchange.v2.c3p0.ComboPooledDataSource] for bean with name 'datasource' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1327)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:594)

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1396)

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:959)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:683)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)

at org.apache.catalina.startup.HostConfig.reload(HostConfig.java:1548)

at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1512)

at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1748)

at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:333)

at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)

at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)

at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1370)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1542)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1552)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1520)

at java.lang.Thread.run(Thread.java:619)

Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1891)

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1734)

at org.springframework.util.ClassUtils.forName(ClassUtils.java:247)

at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)

at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1348)

at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1319)

... 23 more


写回答 关注

9回答

  • 慕仙9184497
    2019-12-12 16:55:36

    升级mybatis-spring版本号1.2.4,问题得到解决

  • 狱刀者
    2018-04-14 11:15:38

    重新name 的名字, 再打前三个字母,使用Alt+/的方式提示选入即可  ,不行再加0.9.2.1的jar  包

  • ONLYWEI
    2017-07-08 15:22:23

    我也出现这样的问题,包什么的都导入了,已启动tomcat后就报错Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSourc

  • Sophomore
    2017-04-23 23:39:15

    因为spring在3.1之后的版本中把 AnnotationSessionFactoryBean与LocalSessionFactoryBean集成到了一起,统一用org\springframework\orm\hibernate4\LocalSessionFactoryBean。 不再有AnnotationSessionFactoryBean类; 但是org.springframework.orm-3.1.1.RELEASE.jar 依然保留有org\springframework\orm\hibernate3这个包,这是为了向下兼容。所以改成hibernate4即可!


  • 仁夏
    2017-04-10 20:05:17

    我解决了:
    Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSourc的解决问题
    解决方法:1.导入c3p0-0.9.2.1.jar和mchange-commons-java-0.2.3.4.jar(有的导入就解决,有的还会报错,报错的看第二步)

    2.对于<!-- 配置连接池 -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><bean>中的class不能直接复制粘贴,要通过“提示”敲出来,如果直接复制或者不按提示敲出来可能还会继续报同样的错误

  • 仁夏
    2017-04-10 19:34:36

    楼主怎么解决的,分享一下

  • 145A
    2017-04-08 10:30:02

    楼主最后是怎么解决的?

    漠燃 回复仁夏

    没有提示啊,包也导入了

    2018-01-19 10:22:10

    共 3 条回复 >

  • qq_败家子_03151170
    2017-02-27 10:29:59


    和楼主 情况一样,我的解决办法是oracle的驱动jar包和数据库版本相同,db.properties文件中加载的驱动类为oracle.jdbc.OracleDriver,这是11g版本的,不行再换oracle.jdbc.driver.OracleDriver试试。

    Night离

    我是Mysql的,很奇怪的是,我再次创建一个工程,把所有的包都放在Liberary竟然也行,我想说如果再不行,干脆把所有的.jar包放到lib下面应该就可以了

    2017-03-01 16:32:47

    共 1 条回复 >

  • Night离
    2017-02-08 16:31:27

    很奇怪,我把c3p0的.jar包放在lib下面就行了,但是放在我自己创建的包就不行。。http://img.mukewang.com/589ad7520001f33602400256.jpg

    表示很奇怪。。。。

基于SSH实现员工管理系统之框架整合篇

本视频教程主要介绍环境搭建和SSH框架整合,逐层深入理解学习

49832 学习 · 344 问题

查看课程

相似问题