Spring學(xué)習(xí)心得(四)
1. Spring對Struts連接:為了在Struts中使用Spring ,需要在Struts的congfig中加入
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
2. 對于action的Spring的應(yīng)用有兩種方法:
a) Extends ActionSupport,使用其中的getWebApplicationContext()得到ApplicationContext,在通過getBean()方法得到所需要的類,不過這樣的話Struts就和Spring耦合在一起了。
b) 重新Delegating actions :在Struts的congfig進(jìn)行配置:
<action path="/XXXX"
type="org.springframework.web.struts.DelegatingActionProxy"/>
然后在Spring中進(jìn)行bean的配置:
<bean name="/XXXX"
這里為需要用到的class,通過Ioc來進(jìn)行配置
|
class="XXXXXXXX">
<property name="YYYY">
<ref bean="YYYY"/>
</property>
</bean>
<bean id="YYYY" class="YYYYYY">
</bean>
當(dāng)然也可以在struts中加入
<controller processorClass=
"org.springframework.web.struts.DelegatingRequestProcessor"/>
這樣就只需要寫
<action path="/XXXX"/>就可以了,DelegatingRequestProcessor能夠自動分派