我在运行测试用例时在我的项目中使用Spring 4.3和hibernate 3.6.7我收到如下错误。有人可以解释一下我需要在代码中进行更改的地方。
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerHibernate' defined in class path resource [com/ikam/rix/test/BaseIntegrationUnitTestCaseContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/service/ServiceRegistry
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
... 25 more
applicationContext.xml:请在下面找到applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="transactionManagerHibernate" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryTest" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceTest" />
</bean>
<bean id="dataSourceTest" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = ****-lx2217.ikamdt.com)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = ****.ikamDT.COM)))" />
<property name="username" value="**" />
<property name="password" value="**" />
</bean>
<bean id="systemParameters" class="com.ikam.rix.common.config.facade.impl.DefaultSystemParameters" />
<bean id="batchKeyGenerator" class="com.ikam.rix.common.batch.pub.impl.DefaultBatchKeyGenerator" />
<bean id="batchPostProcessor" class="com.ikam.rix.common.batch.pub.impl.DefaultBatchPostProcessor" />
<bean id="batchQueuer" class="com.ikam.rix.common.batch.pub.impl.DefaultBatchQueuer" />
<bean id="batchLogger" class="com.ikam.rix.common.batch.pub.impl.DefaultBatchLogger" />
<bean id="batchConfiguration" class="com.ikam.rix.common.batch.pub.impl.DefaultBatchConfigurationImpl" />
<bean id="dataIntegrationKeyGenerator" class="com.ikam.rix.common.dataintegration.impl.DefaultDataIntegrationKeyGenerator" />
<bean id="subscriptionKeyGenerator" class="com.ikam.rix.common.subscription.SubscriptionKeyGeneratorTestImpl" />
<bean id="idrsJobKeyGenerator" class="com.ikam.rix.common.idrs.IdrsJobKeyGeneratorTestImpl" />
<bean id="configParameterCache" class="com.ikam.rix.common.config.cache.impl.DefaultConfigParameterCache" />
<bean id="sessionFactoryTest" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceTest" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">false</prop>
</props>
</property>
</bean>
</beans>
答案 0 :(得分:3)
看起来像WEB-INF \ lib文件夹中找不到类org.hibernate.service。可能你错过了hibernate-core
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.2.Final</version>
</dependency>