2015-10-15 82 views
0

請注意我已經嘗試了以前的帖子,但他們不適合我。使用名稱'transactionManager創建bean時出錯:BeanCreationException

我的Spring和Hibernate配置有問題。

我認爲原因是因爲它無法連接到我的數據庫,但我有我的屬性文件中的憑據都是正確的。 MySQL版本是5.5.44,Spring版本是4.0.2和Hibernate版本是4.2.7.Final

這是我的tomcat的錯誤。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Cannot resolve reference to bean 'mySessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: com.mchange.v2.async.ThreadPoolAsynchronousRunner.<init>(IZLjava/util/Timer;Ljava/lang/String;)V 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.2.RELEASE.jar:na] 
15-Oct-2015 13:22:45.620 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.2.RELEASE.jar:na] 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.2.RELEASE.jar:na] 
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE] 
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE] 
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.2.RELEASE.jar:4.0.2.RELEASE] 
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729) [catalina.jar:8.0.24] 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) [catalina.jar:8.0.24] 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.0.24] 
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) [catalina.jar:8.0.24] 
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) [catalina.jar:8.0.24] 
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) [catalina.jar:8.0.24] 
15-Oct-2015 13:22:45.625 SEVERE [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [/service] startup failed due to previous errors 
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1648) [catalina.jar:8.0.24] 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80] 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80] 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80] 
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80] 
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.24] 
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.7.0_80] 
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.7.0_80] 
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:463) [catalina.jar:8.0.24] 
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:413) [catalina.jar:8.0.24] 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80] 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80] 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80] 
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80] 
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) [tomcat-coyote.jar:8.0.24] 
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.7.0_80] 
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.7.0_80] 
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487) [na:1.7.0_80] 
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:97) [na:1.7.0_80] 
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328) [na:1.7.0_80] 
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420) [na:1.7.0_80] 
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848) [na:1.7.0_80] 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80] 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_80] 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_80] 
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_80] 
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) [na:1.7.0_80] 
at sun.rmi.transport.Transport$2.run(Transport.java:202) [na:1.7.0_80] 
at sun.rmi.transport.Transport$2.run(Transport.java:199) [na:1.7.0_80] 
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_80] 
at sun.rmi.transport.Transport.serviceCall(Transport.java:198) [na:1.7.0_80] 
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:567) [na:1.7.0_80] 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828) [na:1.7.0_80] 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.access$400(TCPTransport.java:619) [na:1.7.0_80] 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:684) [na:1.7.0_80] 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:681) [na:1.7.0_80] 
at java.security.AccessController.doPrivileged(Native Method) [na:1.7.0_80] 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:681) [na:1.7.0_80] 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_80] 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_80] 
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80] 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: com.mchange.v2.async.ThreadPoolAsynchronousRunner.<init>(IZLjava/util/Timer;Ljava/lang/String;)V 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320) ~[spring-beans-4.0.2.RELEASE.jar:na] 
... 62 common frames omitted 
Caused by: java.lang.NoSuchMethodError: com.mchange.v2.async.ThreadPoolAsynchronousRunner.<init>(IZLjava/util/Timer;Ljava/lang/String;)V 
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.createTaskRunner(C3P0PooledConnectionPoolManager.java:145) ~[c3p0-0.9.2.1.jar:na] 
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.poolsInit(C3P0PooledConnectionPoolManager.java:174) ~[c3p0-0.9.2.1.jar:na] 
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.<init>(C3P0PooledConnectionPoolManager.java:295) ~[c3p0-0.9.2.1.jar:na] 
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getPoolManager(AbstractPoolBackedDataSource.java:520) ~[c3p0-0.9.2.1.jar:na] 
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140) ~[c3p0-0.9.2.1.jar:na] 
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] 
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] 
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] 
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:76) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] 
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:160) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] 
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:132) ~[hibernate-core-4.2.7.Final.jar:4.2.7.Final] 
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1822) ~[hibernate-core-4.2.7.Final.jar:na] 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1780) ~[hibernate-core-4.2.7.Final.jar:na] 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1865) ~[hibernate-core-4.2.7.Final.jar:na] 
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343) ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE] 
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431) ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE] 
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416) ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.2.RELEASE.jar:na] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.2.RELEASE.jar:na] 
... 69 common frames omitted 

這是我的根上下文

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns="http://www.springframework.org/schema/beans" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 

<context:property-placeholder location="classpath:props.properties"/> 
<tx:annotation-driven transaction-manager="transactionManager"/> 

<bean id="transactionManager" 
     class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
    <property name="sessionFactory" ref="mySessionFactory"/> 
</bean> 

<bean id="mySessionFactory" 
     class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
    <property name="dataSource" ref="myDataSource"/> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">${locationdb.hibernate.dialect}</prop> 
      <prop key="hibernate.show_sql">true</prop> 
      <prop key="hibernate.hbm2ddl.auto">update</prop> 
      <prop key="hibernate.current_session_context_class"> 
       org.springframework.orm.hibernate4.SpringSessionContext 
      </prop> 
     </props> 
    </property> 
    <property name="packagesToScan"> 
     <list> 
      <value>com.mypackage</value> 
     </list> 
    </property> 
</bean> 

<!-- Location DB Datasource --> 
<!-- When changing between database types, take note: 
     * Change the driverClass and driverClassName below. 
     * Update props.properties as needed (see: endpoint and Hibernate dialect) 
--> 

<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
     destroy-method="close"> 
    <property name="driverClass" value="com.mysql.jdbc.Driver"/> 
    <property name="jdbcUrl" value="${locationdb.endpoint}"/> 
    <property name="user" value="${locationdb.username}"/> 
    <property name="password" value="${locationdb.password}"/> 

    <property name="acquireIncrement" value="${locationdb.c3p0.acquireIncrement}"/> 
    <property name="minPoolSize" value="${locationdb.c3p0.minPoolSize}"/> 
    <property name="maxPoolSize" value="${locationdb.c3p0.maxPoolSize}"/> 
    <property name="maxIdleTime" value="${locationdb.c3p0.maxIdleTime}"/> 
</bean> 


<!-- Location DB MySQL Datasource --> 
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/> 
    <property name="url" value="${locationdb.endpoint}"/> 
    <property name="username" value="${locationdb.username}"/> 
    <property name="password" value="${locationdb.password}"/> 
</bean> 


<bean id="jedisConnFactory" 
     class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" 
     p:hostName="${jedis_endpoint}" 
     p:port="${jedis_endpoint_port}" 
     p:timeout="${jedis_timeout}" 
     p:usePool="true" 
     p:poolConfig-ref="jedisPoolConfig"/> 

<bean id="serializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/> 

<bean id="redisTemplate" 
     class="org.springframework.data.redis.core.RedisTemplate" 
     p:connectionFactory-ref="jedisConnFactory" 
     p:defaultSerializer-ref="serializer"/> 

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig" 
     p:maxTotal="150" 
     p:minIdle="5" 
     p:maxIdle="15"/> 

<!-- Job Manager --> 
<bean id="jobManager" class="com.mypackage.restws.controllers.jobs.JobManager"/> 


<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/> 

,這是我props.properties

locationdb.hibernate.dialect=org.hibernate.dialect.MySQLDialect 

locationdb.endpoint=jdbc:mysql://localhost/locationdb 
locationdb.username=root 
locationdb.password=root 

locationdb.c3p0.acquireIncrement=1 
locationdb.c3p0.minPoolSize=1 
locationdb.c3p0.maxPoolSize=10 
locationdb.c3p0.maxIdleTime=200 

optout.endpoint=https://localhost:8443/ 

我的朋友有他們的項目設置成功,但我是有這個錯誤。有什麼我應該考慮在配置?

+0

看起來像不兼容的jar:'java.lang.NoSuchMethodError com.mchange.v2.async.ThreadPoolAsynchronousRunner。 (IZLjava/util/Timer; Ljava/lang/String;)V' – Jens

+0

看起來你有一個非工作版本的C3P0。我會建議像HikariCP這樣的不同的數據源來代替C3P0。 –

+0

@ M.Deinum我有C3P0的最新版本,我所有的朋友的工作站都在工作。是否有我應該在我的設備或任何設置中設置的配置? – Aaron

回答

1

這似乎與庫的版本不兼容。在服務器啓動的JVM參數中使用"-verbose:class"是一個非常好的(但是詳細的)方法。這會生成很多日誌,所以我更願意將它輸出到服務器啓動命令行中的文件。在仔細搜索相關類時,日誌還會打印出jar文件,並且它是類加載器選擇此類的位置。這可能暗示什麼是兼容性問題。

+0

這工作,但我沒有使用詳細。我有兩個c3p0的jar,一個來自hibernate和c3p0的mchange。我從Hibernate中刪除了一個 – Aaron

相關問題