java 异常问题 No bean named 'sessionFactory' is defined 和 initialize a collection of role
2014-08-24 11:20
501 查看
关于java的“No bean named 'sessionFactory' is defined ” 频繁的出现在与SHH框架中或是在与Sping+JPA底层使用了HIbernate annotation 的实现;出现异常的原因是找不到sessionFactory bean.
原因有如下:
1、在Many-to-one 或是many-to-many 时候 我们设置了fetchType=“lazy” 延时加载。解决问题的方法在web.xml中,加入 openSessionInView过滤器 ,OpenSessionInViewFilter的主要功能是用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。目的是为了实现"Open Session in View"的模式。例如:它允许
在事务提交之后延迟加载显示所需要的对象。
OpenSessionInViewFilter 过滤器将 Hibernate Session 绑定到请求线程中,它将自动被 Spring 的事务管理器探测到。所以 OpenSessionInViewFilter 适用于 Service 层使
(其中的filter-class 注意对号入座 我使用的是Hibernate 所以filter-calss :<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
如果你用的是JPA:<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
)
2、虽然前面已经加入了OpenSessionInViewFilter ,但是也可以是报出sessionFactory not defited;
原因很简单————名称不匹配,OpenSessionInViewFilter模式使用Bean.xml 里面id="sessionFactory "的Bean ,这时如果你的sessionfactory Bean 不叫做这个名,它自然报出Bean 找不到;
原因有如下:
1、在Many-to-one 或是many-to-many 时候 我们设置了fetchType=“lazy” 延时加载。解决问题的方法在web.xml中,加入 openSessionInView过滤器 ,OpenSessionInViewFilter的主要功能是用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。目的是为了实现"Open Session in View"的模式。例如:它允许
在事务提交之后延迟加载显示所需要的对象。
OpenSessionInViewFilter 过滤器将 Hibernate Session 绑定到请求线程中,它将自动被 Spring 的事务管理器探测到。所以 OpenSessionInViewFilter 适用于 Service 层使
(其中的filter-class 注意对号入座 我使用的是Hibernate 所以filter-calss :<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
如果你用的是JPA:<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
)
<!-- 用于处理延时加载问题 openSessionInView过滤器,该过滤器必须在struts过滤器之前配置--> <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
2、虽然前面已经加入了OpenSessionInViewFilter ,但是也可以是报出sessionFactory not defited;
原因很简单————名称不匹配,OpenSessionInViewFilter模式使用Bean.xml 里面id="sessionFactory "的Bean ,这时如果你的sessionfactory Bean 不叫做这个名,它自然报出Bean 找不到;
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
相关文章推荐
- java 不寻常的问题 No bean named 'sessionFactory' is defined 和 initialize a collection of role
- java 异常问题 No bean named 'sessionFactory' is defined
- java 异常 No bean named 'sessionFactory' is defined
- 由OpenSessionInViewFilter引起的No bean named 'sessionFactory' 异常
- HTTP Status 500 - No bean named 'sessionFactory' is defined
- No bean named 'sessionFactory' is defined
- 关于No bean named 'sessionFactory' is defined的诡异事件
- No bean named 'sessionFactory' is defined
- No bean named 'sessionFactory' is defined
- 由OpenSessionInViewFilter引起的No bean named 'sessionFactory' 异常
- 由OpenSessionInViewFilter引起的No bean named 'sessionFactory' 异常
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined
- No bean named 'userService' is defined 问题解决 maven ssh
- No bean named 'MysessionFactory' is defined问题的解决
- 关于NoSuchBeanDefinitionException: No bean named 'xxxx' is defined问题解决
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined
- JPA中的failed to lazily initialize a collection of role:xxxx no session or session was closed异常分析与解决
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is d
- java 异常 No bean named 'sessionFactory' is defined