日期:2014-05-20  浏览次数:20886 次

spring3.1RC和hibernate4.0一起用,报错,请高人指点一下,是什么地方出错了?
applicationContext.xml中相关的配置如下:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"  
destroy-method="destroy">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedPackages" value="classpath:/com/test/spring/hibernate/bean/"/>
<property name="annotatedClasses">
<list>
<value>com.test.spring.hibernate.bean.Catbean</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="catDao"  
class="com.test.spring.hibernate.bean.CatBeanDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>



TestSpringOrmRun.java代码如下:

public class TestSpringOrmRun {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("deprecation")
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));

ICatDao catDao = (ICatDao)factory.getBean("catDao");
Catbean catbean = new Catbean();
catbean.setName("Hello Kitty");
catbean.setCreateDate(new Date());
catDao.createCat(catbean);

List<Catbean> catList = catDao.listCats();
for(Catbean c : catList)
{
System.out.println("Name:" + c.getName());
}

}

}

上面的代码没有编译错误。上面的代码运行报下面的错误,请问什么原因?


Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cache/CacheProvider
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1350)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1111)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:520)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:459)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at com.test.spring.hibernate.test.TestSpringOrmRun.main(TestSpringOrmRun.java:22)