struts2 spring Junit Maven整合运行说明_培训.docVIP

  • 1
  • 0
  • 约7.69千字
  • 约 10页
  • 2019-10-10 发布于江西
  • 举报

struts2 spring Junit Maven整合运行说明_培训.doc

Woyo Java EE项目整合方案说明 DOC 第 PAGE 2 页 共 NUMPAGES 10 页 PAGE PAGE 2 Java EE项目整合方案说明 修改记录 目 录 TOC \o 1-3 \h \z \u 1.整合技术框架说明 3 2.项目搭建Step by Step 3 2.1整合Spring和Strut2 3 2.2使用Junit4.7测试Action和Service类 5 PAGE 6 PAGE 5 1.整合技术框架说明 Struts2.1.8.1 Spring3.0.1.RELEASE Junit4.7 Maven2 为了说明如何整合这些技术组合成一个JAVA EE项目框架,我实现了一个实现登录功能的简单项目。 本文假设读者已经具备了基础JAVA知识并掌握了这些框架安装使用的操作。 2.项目搭建Step by Step 2.1整合Spring和Strut2 1.在src\main\resources路径下的struts.properties中设置struts.objectFactory属性值 文件名:struts.properties struts.objectFactory = spring 或者是在XML文件中进行常量配置 文件名:struts.xml struts ?????? constant name=struts.objectFactory value=spring / /struts 2.src\main\webapp\WEB-INF路径下,配置Spring监听器 文件名:web.xml listener ?????? listener-classorg.springframework.web.context.ContextLoaderListener/listener-class /listener 通过Spring配置来注册对象 文件名:applicationContext-config.xml import resource=classpath*:context/applicationContext-dataAccess.xml / !-- 加载其他Service/module等配置文件 -- import resource=classpath*:service/applicationContext-*.xml / import resource=classpath*:dao/applicationContext-*.xml / 这里将数据库访问信息以及service,dao层的类注册配置文件在这里做了import。这样就可以拥有更多的Spring配置文件。 在web.xml中 进行下列设置,从而使Spring的ApplicationContext通过匹配所给定模式的文件来初始化对象 !-- 用来定位Spring XML文件的上下文配置 -- !-- 加载Srping配置文件 -- context-param param-namecontextConfigLocation/param-name param-valueclasspath*:context/applicationContext-config.xml/param-value /context-param 加入struts2的配置 filter !--过滤器名字 -- filter-namestruts2/filter-name !-- 过滤器支持的struts2类 -- filter-class org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter /filter-class /filter filter-mapping !--过滤器拦截名字 -- filter-namestruts2/filter-name !--过滤器拦截文件路径名字 -- url-pattern/*/url-pattern /filter-mapping 3.修改你的Struts配置文件,将action的class属性设置为spring配置文件中的bean id 文件名:struts.xml package name=login extends=struts !-- Action名字,类以及导航页面定义 -- !-- 通过Action类处理才导航的的Action定义 -- action name=login class=loginAction result name=message/jsp/common/alertMessage.jsp/resul

文档评论(0)

1亿VIP精品文档

相关文档