contextloaderlistenerSpring里的监听有<listener></listener>是什么作用?? 小弟初学,通俗的讲吧

contextloaderlistener  时间:2021-06-02  阅读:()

ContextLoaderListener监听器有什麽用?

ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。

因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。

至于ApplicationContext.xml这个配置文件部署在哪,如何配置多个xml文件,书上都没怎么详细说明。

现在的方法就是查看它的API文档。

在ContextLoaderListener中关联了ContextLoader这个类,所以整个加载配置过程由ContextLoader来完成。

看看它的API说明 第一段说明ContextLoader可以由 ContextLoaderListener和ContextLoaderServlet生成。

如果查看ContextLoaderServlet的API,可以看到它也关联了ContextLoader这个类而且它实现了HttpServlet。

这个接口 第二段,ContextLoader创建的是 XmlWebApplicationContext这样一个类,它实现的接口是WebApplicationContext->ConfigurableWebApplicationContext->ApplicationContext-> BeanFactory这样一来spring中的所有bean都由这个类来创建 第三段,讲如何部署applicationContext的xml文件,如果在web.xml中不写任何参数配置信息,默认的路径是"/WEB-INF/applicationContext.xml,在WEB-INF目录下创建的xml文件的名称必须是applicationContext.xml。

如果是要自定义文件名可以在web.xml里加入contextConfigLocation这个context参数: view plaincopy to clipboardprint? <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/classes/applicationContext-*.xml </param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/classes/applicationContext-*.xml </param-value> </context-param> 在<param-value> </param-value>里指定相应的xml文件名,如果有多个xml文件,可以写在一起并一“,”号分隔。

上面的applicationContext-*.xml采用通配符,比如这那个目录下有applicationContext-ibatis-base.xml,applicationContext-action.xml,applicationContext-ibatis-dao.xml等文件,都会一同被载入。

由此可见applicationContext.xml的文件位置就可以有两种默认实现: 第一种:直接将之放到/WEB-INF下,之在web.xml中声明一个listener、 第二种:将之放到classpath下,但是此时要在web.xml中加入<context-param>,用它来指明你的applicationContext.xml的位置以供web容器来加载。

按照Struts2 整合spring的官方给出的档案,写成: view plaincopy to clipboardprint? <!-- Context Configuration locations for Spring XML files --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> </context-param>

myeclipse提示undefined attribute name "java.util."错误怎么解决

经过研究发现解决之道很简单,打开部署描述符。

把servlet版本号改为2.4或以上即可。

既 Xml代码 <web-app id="WebApp_9" version="2.4" xmlns="/xml/ns/j2ee" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/xml/ns/j2ee/xml/ns/j2ee/web-app_2_4.xsd"> <listener> <listener-class&.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/beans-all.xml</param-value> </context-param> <filter> <filter-name>encodingFilter</filter-name> <filter-class&.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter> <filter-name>hibernateFilter</filter-name> <filter-class> .springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <servlet> <servlet-name>beans</servlet-name> <servlet-class&.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>beans</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- session timeout --> <session-config> <session-timeout>10</session-timeout> </session-config> <!-- Index Page --> <e-file-list> <e-file>index.jsp</e-file> <e-file>index.html</e-file> </e-file-list> <!-- Error Page --> <error-page> <error-code>500</error-code> <location>/page/error.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/page/404.jsp</location> </error-page> <error-page> <error-code>403</error-code> <location>/page/403.jsp</location> </error-page> </web-app>

Spring里的监听有<listener></listener>是什么作用?? 小弟初学,通俗的讲吧

listener标签是用于监听的,ContextLoaderListener实现了ServletContextListener接口,可以监听所有的servlet,好想还有关于监听session的,request的等等的接口,具体名称忘了。

这样对于每个用户请求,都被contextLoaderlistener监听到,执行请求都要先经过这个类,这个类肯定是做些转移的操作,把由servlet容器管理的类转到spring容器去管理,首先肯定是产生spring容器,spring容器起作用了

TabbyCloud周年庆&七夕节活动 美國INAP 香港CN2

TabbyCloud迎来一周岁的生日啦!在这一年里,感谢您包容我们的不足和缺点,在您的理解与建议下我们也在不断改变与成长。为庆祝TabbyCloud运营一周年和七夕节,TabbyCloud推出以下活动。TabbyCloud周年庆&七夕节活动官方网站:https://tabbycloud.com/香港CN2: https://tabbycloud.com/cart.php?gid=16购买链...

RackNerd:特价美国服务器促销,高配低价,美国多机房可选择,双E526**+AMD3700+NVMe

racknerd怎么样?racknerd今天发布了几款美国特价独立服务器的促销,本次商家主推高配置的服务器,各个配置给的都比较高,有Intel和AMD两种,硬盘也有NVMe和SSD等多咱组合可以选择,机房目前有夏洛特、洛杉矶、犹他州可以选择,性价比很高,有需要独服的朋友可以看看。点击进入:racknerd官方网站RackNerd暑假独服促销:CPU:双E5-2680v3 (24核心,48线程)内存...

百驰云(19/月),高性能服务器,香港三网CN2 2核2G 10M 国内、香港、美国、日本、VPS、物理机、站群全站7.5折,无理由退换,IP免费换!

百驰云成立于2017年,是一家新国人IDC商家,且正规持证IDC/ISP/CDN,商家主要提供数据中心基础服务、互联网业务解决方案,及专属服务器租用、云服务器、云虚拟主机、专属服务器托管、带宽租用等产品和服务。百驰云提供源自大陆、香港、韩国和美国等地骨干级机房优质资源,包括BGP国际多线网络,CN2点对点直连带宽以及国际顶尖品牌硬件。专注为个人开发者用户,中小型,大型企业用户提供一站式核心网络云端...

contextloaderlistener为你推荐
winhttp什么是WinHTTP数据监测监测局是做什么的?搜索引擎的概念搜索引擎营销的概念是什么?seo优化技术做seo需要懂什么技术?自定义表情qq自定义表情谷歌图片识别如何打开PICASA头像识别功能?labelforhtml中label是什么意思啊?移动硬盘文件或目录损坏且无法读取移动硬盘文件或目录损坏且无法读取怎么办??点心os点心 OS 用户界面(UI)的设计理念是什么?什么是网络地址请问电脑显示正在获取网络地址是什么意思怎么办
济南域名注册 免费注册网站域名 搬瓦工官网 腾讯云数据库 免费ddos防火墙 52测评网 创梦 合租空间 tna官网 河南移动网 台湾谷歌 申请网页 海外空间 ebay注册 服务器防御 美国asp空间 forwarder cdn加速 cc加速器 国内免备案cdn 更多