分析:大家可以看到,在這種方式之下,我們的Struts Action類和Spring是低耦合的,它僅僅依賴了Spring提供的反向控制(IoC)機制把CourceService注入到了我們的Action中.到此,大家肯定會有一個疑問:那就是Spring到底是如何提供IoC反向控制的呢?回答這個問題,我們需要完成兩個步驟的配置:
(1).在struts-config.xml中注冊Struts Action.但要注意的是我們在這里注冊的是代理Action.幸運的是,我們不必親自編寫這個類.因為Spring已經通過org.springframework.web.struts.DelegatingActionProxy提供了這個代理的Action.具體的配置方法如下:
<action type="org.springframework.web.struts.DelegatingActionProxy" path="/listCourses">
(2)將真正的Struts Action作為一個Spring Bean并在Spring上下文配置文件中作為一個Bean注冊之.并將Action所要引用的courceService注入給它.
<bean class="com.eRedCIP.web.CourceAction" name="/listCourses">
<property name="">
<ref bean="courseService">
</property>
</bean>
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/