OpenSessionInView的配置

众所周知hibernate的lazy问题。当session关闭后,再想延迟加载对象就会报出 no session or session was closed的错误
后spring提供了OpenSessionInView解决了此问题,大概原理是这样的首先获得SessionFactory,然后通过SessionFactory获得一个Session。然后执行真正的Action代码,最后根据情况将Hibernate的Session进行关闭。

配置方法
1.filter配置
web.xml
	<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>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>


2.将struts以plugin形式注入到spring的ioc中
struts-config.xml

<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/action-servlet.xml" />
</plug-in>


3.action beans
action-servlet.xml

<bean name="/orgInit/orgInit"
class="jarod.javaeye.action.orgInit.OrgInitAction" >
<property name="orgInitService">
<ref bean="orgInitServiceImpl" />
</property>
</bean>

...

我测试的结果是不可将action beans放入application-context.xml中,直接注入spring

相关参考和前辈出现过的问题
[url]http://www.iteye.com/topic/17501[/url]性能问题
[url]http://www.iteye.com/topic/15057[/url]采用struts配置中容易出现的问题
[url]http://www.iteye.com/topic/9668[/url]有关OpenSessionInView模式的问题
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值