BeanCreationException:创建名称为“sessionFactory”的 bean 时出错;

发布于 2024-11-25 10:38:15 字数 3191 浏览 0 评论 0原文

我在尝试创建会话工厂时遇到以下问题。

javax.servlet.ServletException:org.springframework.beans.factory.BeanCreationException:创建类路径资源 [com/virtusa/ideas/util/spring.xml] 中定义的名为“userDao”的 bean 时出错:无法解析对的引用bean 'sessionFactory' 同时设置 bean 属性 'factory';嵌套异常是 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>

有人可以帮忙吗?

Im getting the following issue when trying to create session factory.

javax.servlet.ServletException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'factory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'factory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/virtusa/ideas/util/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer
root cause
java.lang.NoClassDefFoundError: Could not initialize class 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>

Can anyone help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疏忽 2024-12-02 10:38:15

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

You are missing cglib jar which is required by hibernate for code-generation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文