Spring学习笔记-----(Struts与Spring的结合)

1、首先在struts-config.xml中加入下面代码:
<struts-config>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>

注:为 Struts 的 ActionServlet 装载 Spring 应用程序环境。就像添加任何其他插件一样,简单地向您的 struts-config.xml 文件添加该插件。
2、对Action进行配置
<action-mappings>
<action path="/login"
type="org.springframework.web.struts.DelegatingActionProxy"
name="loginForm">
<forward name="success" path="/main.jsp" />
<forward name="failure" path="/login.jsp" />
</action>
</action-mappings>

注:,Struts 在运行期加载的实际上是DelegatingActionProxy , 而
DelegatingActionProxy则实现了针对实际Action的调用代理,Struts最终调用的将是由Spring
管理的Action实例。
3、在beans.xml中配置的要点:
<bean name="/login" class="net.xiaxin.action.LoginAction"
singleton="false">
<property name="userDAO">
<ref bean="userDAOProxy" />
</property>
</bean>
注意这里的bean要定义成name,而不要定义成id

你可能感兴趣的:(spring)