BeanCreationException:创建名称为“sessionFactory”的 bean 时出错;
我在尝试创建会话工厂时遇到以下问题。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少 hibernate 代码生成所需的 cglib jar。
You are missing cglib jar which is required by hibernate for code-generation.