org.springframework.web.context.ContextLoaderListener的作用

  如果你想要在自己定义的servlet类别中使用spring的容器功能,则也可以使用org.springframework.web.context.ContextLoaderListener,例如在web.xml使用 <listener>标签;来定义:

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

ContextLoaderListener会预读如果在web.xml中applicationContext.xml,不写任何参数配置信息,默认的路径是”/WEB-INF/applicationContext.xml,你可以制定自己定义的文档,只要在<context-param>中指定"contextConfigLocation"参数,例如:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:applicationContext.xml,/WEB-INF/httpinvoker-servlet.xml
        </param-value>
    </context-param>

接着你可以在自定义的servlet中使用:

WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());

WebApplicationContext实作了applicationContext的介面 ,是spring专门为servlet web应用程序设计的applicationContext实作类别,在取得WebApplicationContext后,你可以利用它来取得Bean定文档的bean实例,例如:

Date date = (Date)getBean("dateBean");

在不支持listener的容器上你可以使用org.springframework.web.contextContextLoaderServlet代替org.springframework.web.context.ContextLoaderListener

的设定

 

 

转载于:https://www.cnblogs.com/taotaoyan/archive/2013/05/09/3068523.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值