Spring web 的通用配置

通用配置

Web 层只是很多层中的一层...它是服务器端应用的一个入口.

所有 Web 框架都适用的 Spring 配置

在我们的web应用里面找到你的web.xml 在里面加入如下配置就可以启动spring容器了

加载 Spring 配置文件
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

初始化spring容器
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Listener 是在 Servlet API 2.3 版本中才加入的 所以你的版本必须在2.3(或)之上

如果你用的版本在这个之下 那么你就得这么配置了

加载 Spring 配置文件
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

初始化spring容器
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

通过struts1.x来启动spring容器

初始化spring容器
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
  <set-property property="contextConfigLocation"
      value="/WEB-INF/action-servlet.xml.xml,/WEB-INF/applicationContext.xml"/>
</plug-in>

 Action 依赖关系  把action 交给spring管理
<controller>
  <set-property property="processorClass"
      value="org.springframework.web.struts.DelegatingRequestProcessor"/>
</controller>

<action path="/users" .../>
你必须在 action-servlet.xml 中将 Action bean 的名字定义为 “/users”:
<bean name="/users" .../>

这样全部的action就可以由spring来管理了

若果你要对指定的某一个action交给spring来管理的话那么你可以这样配置

<action path="/user" type="org.springframework.web.struts.DelegatingActionProxy"> </action>

但是不推荐这么搞,如果这么做的话 你要是有多个action的话 你就得每个的type指定为 org.springframework.web.struts.DelegatingActionProxy

个人觉得有些麻烦 呵呵





转载于:https://my.oschina.net/58685474/blog/51944

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值