首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

总结spring和struts整合的三类方式

2012-12-25 
小结spring和struts整合的三类方式?整合spring和hibernate的三种方式,小结之.?1) 在struts中使用webapplic

小结spring和struts整合的三类方式

?整合spring和hibernate的三种方式,小结之.

?

1) 在struts中使用webapplicationcontext调用spring
??? 声明web.xml,声明一个contextloadlistener,让在启动时执行该listener,读spring的配置文件

??? <listener>
??<listener-class>
???org.springframework.web.context.ContextLoaderListener
??</listener-class>
?</listener>

? 再增加一个contextConfigLocation
?? <context-param>
??<param-name>contextConfigLocation</param-name>
??<param-value>/WEB-INF/applicationContext*.xml</param-value>
?</context-param>

?WebApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext);

? UserBean userbean=(UserBean)ctx.getBean("userbean");

?

2) 将struts的action托管给spring
?????? 这也是很经常用的.用法是
??? 在struts-config.xml中,加载contextloaderplugin插件,加载spring配置

?

<controller processor/>


??<plug-in
??className="org.springframework.web.struts.ContextLoaderPlugIn">
??<set-property property="contextConfigLocation"
??value="/WEB-INF/applicationContext.xml" />
??</plug-in>

? 这样的话,把struts的action完全托管给spring了,在struts-config.xml中

??? <action path="/user/"..>,这里不需要再用class了,

但在application-context.xml中,则要有
?? <bean name="/user"..../>了.

?

3 继承spring的actionsupport类
????? 比如

?? public class aaaa extends DispatchActionSupport

?{

??????? ......

?

????????WebApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext);

? UserBean userbean=(UserBean)ctx.getBean("userbean");

?

?

?

?? }
???

热点排行