使用spring 的action-servlet.xml解决struts线程问题

<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>

你可能感兴趣的:(spring,xml,bean,servlet,struts)