web.xml(ContextLoaderListener)

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

  </listener>

1.ContextLoaderListener的作用:在启动Web容器时,自动装配Spring applicationContext.xml的配置信息。

参考文档:http://blog.csdn.net/panxuying123/article/details/16910885

网上通常说,listener通常会和context-param一起配合使用,看了上面的文档,如下:

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

在全局参数里面配置了classpath:applicationContext.xml的路径,在listener中配置了ContextLoaderListener这个类,之所以说这个类的作用是自动装配Spring applicationContext.xml的配置信息,是因为它实现了一个ServletContextListener接口。在ContextLoaderListener这个监听的类中有个contextInitialized(ServletContextEvent event)的方法,在这个方法中可以通过event.getServletContext().getInitParameter("contextConfigLocation") 来得到context-param 设定的值。所以网上说listener通常会和context-param一起配合使用。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值