带有Hibernate 3注释的Spring 3 - 会话工厂配置

时间:2011-06-28 12:19:10

标签: java hibernate spring

我很少运气配置我的Spring配置文件用于Hibernate Annotations。我一直在看其他帖子,我不确定我错过了什么。我不需要定义配置文件,因为我在会话工厂中使用HibernateProperties正确吗?我收到以下错误:

错误消息

创建名为'HibernateSessionFactory'

的bean时出错

无法实例化bean类[org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean]:构造函数抛出异常;嵌套异常是java.lang.NoClassDefFoundError:org.hibernate.cfg.AnnotationConfiguration

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)

Spring配置

<!--     Defines the hibernate session factory to be used by the hibernate support dao classes -->
<bean id="HibernateSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
    <property name="dataSource" ref="webDataSrc" />
    <property name="annotatedClasses"> 
            <list> 
                    <value>ca.test.Foo</value> 
            </list> 
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="debug">true</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
        </props>
    </property>
</bean>

enter image description here

1 个答案:

答案 0 :(得分:0)

你的类路径上有Hibernate Annotations jar吗?