现在最流行的j2ee的程序,一般都是用struts+spring+hibernate框架做的,spring+hibernate的配置方式很简单,这里就不说了,下面对struts+spring的几种配置方式做个总结,

第一种方式
1.创建BaseAction类,它继承Action类,以后所有action类都继承BaseAction这个类。
   比如:public class BaseAction extends Action {
                  private ApplicationContext applicationContext;
                 //private Service1 service1;
                 //private Service2 service2;
                 public ApplicationContext getApplicationContext() {
                 return applicationContext;
              }
2.在web.xml中加入
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
----------------------------------------------------------------------------------------------
第二种方式
1.所有action类都继承ActionSupport类
2.在web.xml中加入
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
----------------------------------------------------------------------------------------------
第三种方式
1.在struts-config.xml中的所有action的type里写org.springframework.web.struts.DelegatingActionProxy
  而不写action的类路径位置
2.在struts-config.xml中加入
  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
   <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>
  </plug-in> 
3.applicationContext.xml中加入
  <bean name="/struts-config.xml中的action" class="struts-config.xml中的action的真实类路径">
 <property name="业务对象">
  <ref local="代理对象"/>
 </property>
  </bean>
----------------------------------------------------------------------------------------------
第四种方式
1.在struts-config.xml中加入
 <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
 </controller>

2.applicationContext.xml中加入
  <bean name="/struts-config.xml中的action" class="struts-config.xml中的action的类路径">
 <property name="业务对象">
  <ref local="代理对象"/>
 </property>
  </bean>
3.在web.xml中加入
 <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

以上是我所知道的四种配置方式,应该就这四种方式,本人感觉第三种配置方式比较好,通过struts的插件
方式把spring加过来,加多个spring的配置文件比较方更,只要在<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/>的value中通过“,”分隔可以加多个spring的配置方件。

如果你有什么更好的方式,或有什么建议请给我留言。

struts+spring的配置方式总结相关推荐

  1. struts spring hibernate 配置

    web.xml <?xml version="1.0" encoding="GBK"?> <web-app xmlns="http: ...

  2. Spring Bean配置方式之一:Java配置

    简介: Spring bean 是使用传统的 XML 方法配置的.在这篇文章中,您将学习使用基于纯 Java 的配置而非 XML 来编写 Spring bean 并配置它们.本文将介绍可用来配置 be ...

  3. Spring事务配置方式(一) 拦截器方式配置

    一.使用<tx:advice>和<aop:config>配置事务 <!-- 配置事务管理器 --><bean id="transactionMana ...

  4. Spring基于配置方式实现自定义条件装配

    @Profile Spring为我们提供的可以根据当前环境,动态的激活和切换一系列组件的功能 @Profile指定组件在哪个环境的情况下才能被注册到容器中,不指定,任何环境下都能注册这个组件 @Pro ...

  5. spring配置方式:

    spring中配置方式可以完全使用注解也可以完全使用注解实现,但是大部分都是用xml加注解,这样不仅兼顾了效率,也提高了程序的可读性: 但是需要注意的是: 纯注解实现时:需配置扫描: <cont ...

  6. SpringDataJPA教程 三种配置方式

    本教程分为三类配置 1.spring xml配置文件方式 2.spring 注解配置方式 3.springboot 配置方式 1.xml配置方式 引入maven依赖 <dependencies& ...

  7. Spring YAML配置

    Spring YAML配置 使用yaml配置文件是Spring多种配置方式之一,本文介绍使用yaml配置Spring boot多种profile. 1. Spring YAML文件 Spring pr ...

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

    小结spring和struts整合的三类方式 整合spring和hibernate的三种方式,小结之. 1) 在struts中使用webapplicationcontext调用spring     声 ...

  9. spring实战学习(三)配置方式

    spring配置方式有xml配置和注解配置和基于java的配置方式,配置Bean是spring应用的重要一环,依赖注入也是spring实现ioc的核心. xml配置方式 常见的几种注入方式 1.set ...

最新文章

  1. 【c语言】数组逆序排列
  2. 数据结构乐智教学百度云_网易云课堂 - 我的职业课堂
  3. Linux知识点复习
  4. python sqlite3加密_sqlite3加密 - kjpioo的个人空间 - OSCHINA - 中文开源技术交流社区...
  5. tim怎么设置检测到新版本自动安装 tim安全自动更新的开启方法
  6. linux下svn常用指令(转)
  7. 加拿大第二大行TD Bank是如何践行科技战略的?
  8. Visual Studio2013修改IDE集成开发环境视图风格
  9. [Noip2007]Core树网的核
  10. Java Web实战篇-轻松提高千万级数据库查询效率
  11. PHP拼接SQL语句批量更新多个字段
  12. centos7 mysql5.6.35_Centos7.2.1511 编译安装Mysql5.6.35
  13. 【HDU 6274】Master of sequence【二分答案+下取整转换】
  14. 《工程电磁场(第三版)》(倪光正 主编)复习
  15. 机器学习算法(一):基于逻辑回归的分类预测
  16. Could not locate executable null\bin\winutils.exe in the Hadoop binaries解决方式
  17. php mds函数,MDSRank类解析 - linux_hunter的个人页面 - OSCHINA - 中文开源技术交流社区...
  18. 对Word文档中的指定内容进行替换
  19. Excel MATCH函数判断两列包含关系
  20. anmate.css怎么用,animate.css使用方法是什么

热门文章

  1. 基于【CentOS-7+ Ambari 2.7.0 + HDP 3.0】HAWQ数据仓库 使用之 gpfdist协议
  2. SpringBoot—— @ComponentScan
  3. ArcEngine中IFeatureClass.Search(filter, Recycling)方法中Recycling参数的理解
  4. Mysql (一)Mysql 数据库增删改查
  5. Effective stl---笔记
  6. [Jmeter系列]Jmeter源码编译步骤(转)
  7. Device.js——检测设备平台、操作系统的Javascript 库
  8. 路由器中的管理间距和量度参数
  9. 在CentOS7上部署.net core 控制台应用程序部署为后台服务
  10. for、for / in循环