标签:引用 名称 耦合度 span 这一 ext 工作 编写 需要
有了Spring以后,所有对象的创建任务都应该交给Spring容器来完成,这样做不仅是为了降低代码的耦合度,而且可以利用Spring容器作为代理工厂实现代理。
将Spring容器中的bean注入Action中,将Action的创建与管理工作交给Spring容器。
Spring与Struts的整合建立在Spring与Web整合的基础之上。
Struts2提供了与Spring兼容的架包struts2-spring-plugin.jar,整合需要导入该架包。
完成了Spring与Web的整合以后,Spring容器会根据名称将bean注入到action中,这一步完成了将Spring容器中的bean
注入到action中的任务,将action创建与管理工作交给Spring容器的任务还没有完成,在Spring配置文件的编写:
<bean id="springActionName"class="xxxxAction"scope="prototype"> <property name="" ref="">//注入action中引用的 bean </bean>
action是多例的,必须将作用域设为prototype.
<package name=""extends="struts-default"namespace=""> <action name="myAction"class="springActionName"> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </action> </package>
在Struts.xml中通过id引用在Spring容器中创建的Action对象。
标签:引用 名称 耦合度 span 这一 ext 工作 编写 需要
原文地址:http://www.cnblogs.com/tonghun/p/7231220.html