4

我的 spring/hibernate/c3p0/jboss 应用程序遇到了一个非常奇怪的问题。当它启动时,日志显示

16:42:09,219 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator](MSC 服务线程 1-4)HHH000130:实例化显式连接提供程序:org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider

16:42:09,235 INFO [org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider](MSC 服务线程 1-4)HHH010002:C3P0 使用驱动程序:oracle.jdbc.OracleDriver 在 URL:jdbc:oracle:thin:@ ...

但是,当它尝试创建 SessionFactory bean 时,我看到了一点点

16:42:11,219 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator](MSC 服务线程 1-2)HHH000130:实例化显式连接提供程序:org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider

接下来是壮观的堆栈跟踪,以

原因:java.lang.ClassNotFoundException:无法加载请求的类:org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider

休眠.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
    <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.password">...</property>
    <property name="hibernate.connection.url">jdbc:oracle:thin:...</property>
    <property name="hibernate.connection.username">...</property>
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
    <property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
    <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">300</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>
</session-factory>
</hibernate-configuration>

语境:

@Configuration
@EnableTransactionManagement
@ComponentScan("...")
public class PersistenceContext {

    @Bean
    public SessionFactory sessionFactory() throws IOException {
        LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
        sessionFactoryBean.setConfigLocation(new ClassPathResource("hibernate.cfg.xml"));
        sessionFactoryBean.afterPropertiesSet();
        return sessionFactoryBean.getObject();
    }

    @Bean
    public HibernateTransactionManager transactionManager() throws IOException {
        HibernateTransactionManager manager = new HibernateTransactionManager(sessionFactory());
        return manager;
    }
}

持久性.xml

<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="primary" transaction-type="JTA">
    <properties>
        <property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
    </properties>
</persistence-unit>
hibernate version: 4.0.1.Final
spring: 3.2.3.RELEASE
jboss: 7.1.1
c3p0: 0.9.1 (version listed as a dependency of hibernate-c3p0)

编辑 堆栈跟踪:

10:16:51,253 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/...]] (MSC service thread 1-7) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scenarioController' defined in "/C:/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final/bin/content/app.war/WEB-INF/classes/com/.../web/controllers/ScenarioController.class": Unsatisfied dependency expressed through constructor argument with index 0 of type [...dao.interfaces.ScenarioDao]: : Error creating bean with name 'scenarioDaoImpl' defined in "/C:/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final/bin/content/app.war/WEB-INF/classes/com/.../dao/ScenarioDaoImpl.class": Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Error creating bean with name 'sessionFactory' defined in class app.web.config.PersistenceContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory ...web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class ....web.config.PersistenceContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory ....web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scenarioDaoImpl' defined in "/C:/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final/bin/content/....war/WEB-INF/classes/com/.../dao/ScenarioDaoImpl.class": Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Error creating bean with name 'sessionFactory' defined in class com.....web.config.PersistenceContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.....web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class com.....config.PersistenceContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.....web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1045) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_12]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_12]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_12]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scenarioDaoImpl' defined in "/C:/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final/bin/content/....war/WEB-INF/classes/com/.../dao/ScenarioDaoImpl.class": Unsatisfied dependency expressed through constructor argument with index 0 of type [org.hibernate.SessionFactory]: : Error creating bean with name 'sessionFactory' defined in class com.....web.config.PersistenceContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.....web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class com.....web.config.PersistenceContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.....web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:730) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1045) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class com.....web.config.PersistenceContext: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.....web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1025) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:921) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
... 37 more
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory com.....web.config.PersistenceContext.sessionFactory() throws java.io.IOException] threw exception; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
... 50 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.service.jdbc.connections.spi.ConnectionProvider]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:187) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:234) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:91) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:247) [spring-orm-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:373) [spring-orm-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:358) [spring-orm-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at com.....web.config.PersistenceContext.sessionFactory(PersistenceContext.java:23) [classes:]
at com.....web.config.PersistenceContext$$EnhancerByCGLIB$$407e55e5.CGLIB$sessionFactory$1(<generated>) [spring-core-3.2.3.RELEASE.jar:]
at com.....web.config.PersistenceContext$$EnhancerByCGLIB$$407e55e5$$FastClassByCGLIB$$22f280c.invoke(<generated>) [spring-core-3.2.3.RELEASE.jar:]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) [spring-core-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:286) [spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at com.....web.config.PersistenceContext$$EnhancerByCGLIB$$407e55e5.sessionFactory(<generated>) [spring-core-3.2.3.RELEASE.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_12]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_12]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_12]
at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_12]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160) [spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
... 51 more
Caused by: org.hibernate.HibernateException: Could not instantiate connection provider [org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider]
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:190) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:112) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:54) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:177) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
... 77 more
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:187) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
... 81 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at java.lang.ClassLoader.loadClass(ClassLoader.java:307) [rt.jar:1.6.0_12]
at java.lang.ClassLoader.loadClass(ClassLoader.java:252) [rt.jar:1.6.0_12]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
... 82 more

我可以在部署目录中看到 hibernate-c3p0-4.0.1.Final.jar 和 c3p0-0.9.1.jar ,它们肯定被包括在内。我什至打开了 hibernate-c3p0-4.0.1.Final.jar 以确保该类确实在其中,并且正是它应该在的位置。

我一直在调试器中逐步完成。第一次,ModuleClassLoader 为 deployment.tdm-web-proof-of-concept.war:main 成功加载了该类。第二次, org.hibernate:main 的 ModuleClassLoader 正在尝试但未能找到它。我确信这是某种配置问题,休眠模块的类加载器看不到这一点。有什么想法可以指出正确的方向吗?

4

2 回答 2

1

此版本的org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(). 它错误地假设它继承自的休眠类中已弃用的方法将加载加载它的类加载器和 TCCL,这是一个实现细节。相反,此方法仅使用加载它的类加载器,即休眠模块的类加载器。这个类加载器的类路径上没有部署类,所以它抛出了 ClassNotFoundException。

由此,我们可以有把握地说,org.springframework.orm.hibernate4.LocalSessionFactoryBean这个版本的spring不能与这个版本的hibernate 4一起使用。

于 2013-07-03T15:25:02.187 回答
0

来自http://www.mkyong.com/hibernate/hibernate-could-not-find-c3p0connectionprovider/

它相当旧,我想说的是 AS 7 之前的版本,但也可能适用。当然你得把版本和AS中包含的Hibernate相匹配。


从 Hibernate v3.3 开始(如果没记错的话),“C3P0ConnectionProvider”被移动到另一个 jar 文件“hibernate-c3p0.jar”。您需要包含它,以使 Hibernate 支持 c3p0 连接池。

您可以从 JBoss 公共存储库下载“hibernate-c3p0.jar”。

<repositories>
    <repository>
        <id>JBoss repository</id>
        <url>http://repository.jboss.org/nexus/content/groups/public/</url>
    </repository>
</repositories>

<dependencies>
    <!-- Hibernate c3p0 connection pool -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>3.6.3.Final</version>
    </dependency>
</dependencies>
于 2013-06-30T03:30:34.937 回答