`
wiley
  • 浏览: 251942 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

struts+spring整合测试

阅读更多
百事通信息网


struts+spring整合有3种方式,通过查阅资料得知,将servlet action 委托给spring来管理的这种方式优势最为显著.本次struts+spring整合测试就是采用委托的方法。
实施步聚:
首先在struts-config.xml文件中注册spring插件,如下所示。
    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
           <set-property property="contextConfigLocation"     value="/WEB-INF/applicationContext.xml" />
     </plug-in>

其次将所有action标签中type属性设为org.springframework.web.struts.DelegatingActionProxy 也就是将action委托给了spring
因而在spring上下文applicationContext.xml中配置一个于action标签path属性对应的bean(也就是bean的name值等于action的path值),如:
struts-config.xml代码片段
 ......
<action-mappings>
  <action attribute="userForm" input="/user.jsp" name="userForm"
   path="/user" scope="request"
   type="org.springframework.web.struts.DelegatingActionProxy"
   validate="false" />
 </action-mappings>
......

applicationContext.xml代码片段
......
 <bean name="/user" class="com.wiley.struts.action.UserAction" singleton="false" >
  <property name="manage">
   <ref bean="manage" />
  </property>
 </bean>
......

到此基本的配置工作完成了
在测试的过程中遇到servlet action无效,但控制台没有任何的提示,翻遍整个网络,e文看得是一知半解,中文资料很少,对我来说有价值的更少,将log4j增加上去后再次测试,原来是ContextLoaderPlugIn没有找到。在使用MyEclipse搭建spring环境时,请务必将spring-web也导入。
最后将spring-web加入后测试成功。
分享到:
评论
1 楼 tigerphoebe 2008-04-12  
GOO000000000000000G

相关推荐

Global site tag (gtag.js) - Google Analytics