Blog信息 |
blog名称:小鸟吹烟 日志总数:157 评论数量:424 留言数量:-1 访问次数:1257970 建立时间:2006年10月23日 |

| |
[SSH 学习区]使用spring 的action-servlet.xml解决struts线程问题 随笔, 读书笔记, 心得体会, 软件技术
tone 发表于 2007/1/27 10:14:13 |
<bean name="/register" class="com.action.RegisterAction" singleton="false">
<property name="businessService"> <ref bean="businessService"/> </property>
</bean>
RegisterAction是Action的实现类,businessService是业务逻辑,Spring把businessService注入到Action中,在Action中只要写businessService的get和set方法就可以了,同时action的bean设为singleton="false",这样每次新建一个实例,从而解决了Struts中Action的线程同步问题
1.struts 中实现接口
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml" /> </plug-in>
2.将<action type 变为
= "org.springframework.web.struts.DelegatingActionProxy"
3.编写action-servlet.xml 如:
<bean name="/Analyse" class="com.apple.struts.action.IndexAnalyseAction" singleton="false"> <property name="flowService"> <ref bean="flowService"/> //此处对应applicationContext.xml </property> </bean>
4.web.xml中配置
<filter> <filter-name>hibernateFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter>
<filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
|
|