BeanCreationException:创建名为'sessionFactory'的bean时出错

时间:2011-07-20 18:33:24

标签: java hibernate spring java-ee

尝试创建会话工厂时出现以下问题。

  

javax.servlet.ServletException:org.springframework.beans.factory.BeanCreationException:在类路径资源[com / virtusa / ideas / util / spring.xml]中定义名称为'userDao'的bean时出错:无法解析对设置bean属性'factory'时bean'sessionFactory';嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[com / virtusa / ideas / util / spring.xml]中定义名称为'sessionFactory'的bean时出错:init方法的调用失败;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类net.sf.cglib.proxy.Enhancer   根本原因   org.springframework.beans.factory.BeanCreationException:在类路径资源[com / virtusa / ideas / util / spring.xml]中定义名称为'userDao'的bean时出错:在设置bean属性时无法解析对bean'sessionFactory'的引用厂';嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[com / virtusa / ideas / util / spring.xml]中定义名称为'sessionFactory'的bean时出错:init方法的调用失败;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类net.sf.cglib.proxy.Enhancer   根本原因   org.springframework.beans.factory.BeanCreationException:在类路径资源[com / virtusa / ideas / util / spring.xml]中定义名称为'sessionFactory'的bean时出错:init方法的调用失败;嵌套异常是java.lang.NoClassDefFoundError:无法初始化类net.sf.cglib.proxy.Enhancer   根本原因   java.lang.NoClassDefFoundError:无法初始化类net.sf.cglib.proxy.Enhancer

Spring.xml

<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-3.0.xsd" default-autowire="byName">

<!--    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>-->


    <bean id="userDao"
        class="com.virtusa.ideas.util.HibernateUserDAO">
        <property name="factory" ref="sessionFactory" />
    </bean>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="mappingResources">
            <list>
                <value>com/virtusa/ideas/entity/User.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
<!--            <props>
                <prop key="hibernate.dialect">
        org.hibernate.dialect.MySQLDialect
                </prop>
            </props>-->
             <value> 
                hibernate.dialect=org.hibernate.dialect.MySQLDialect
            </value> 
        </property>
    </bean>


    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="url" value="jdbc:mysql://localhost:3306/ideas" />
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>

</beans>

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

你缺少hibernate为代码生成所需的cglib jar。