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容器起作用了

FlashFXP FTP工具无法连接主机常见原因及解决办法

目前,我们都在用哪个FTP软件?喜欢用的是WinSCP,是一款免费的FTP/SFTP软件。今天在帮助一个网友远程解决问题的时候看到他用的是FlashFXP FTP工具,这个工具以前我也用过,不过正版是需要付费的,但是网上有很多的绿色版本和破解版本。考虑到安全的问题,个人不建议选择破解版。但是这款软件还是比较好用的。今天主要是遇到他的虚拟主机无法通过FTP连接主机,这里我就帮忙看看到底是什么问题。一...

Vultr新注册赠送100美元活动截止月底 需要可免费享30天福利

昨天晚上有收到VULTR服务商的邮件,如果我们有清楚的朋友应该知道VULTR对于新注册用户已经这两年的促销活动是有赠送100美元最高余额,不过这个余额有效期是30天,如果我们到期未使用完的话也会失效的。但是对于我们一般用户来说,这个活动还是不错的,只需要注册新账户充值10美金激活账户就可以。而且我们自己充值的余额还是可以继续使用且无有效期的。如果我们有需要申请的话可以参考"2021年最新可用Vul...

Gigsgigscloud($9.8)联通用户优选日本软银VPS

gigsgigsCloud日本东京软银VPS的大带宽配置有100Mbps、150Mbps和200Mbps三种,三网都走软银直连,售价最低9.8美元/月、年付98美元。gigsgigscloud带宽较大延迟低,联通用户的好选择!Gigsgigscloud 日本软银(BBTEC, SoftBank)线路,在速度/延迟/价格方面,是目前联通用户海外VPS的最佳选择,与美国VPS想比,日本软银VPS延迟更...

contextloaderlistener为你推荐
视频压缩算法关于视频压缩的原理?知识分享平台全国知识共享的平台有哪些?华为总裁女儿为啥姓孟总裁文女主姓孟,女主父母抱错孩子,后来将错就错,养父母对女主很好人肉搜索引擎人肉搜索引擎是干什么的?模式识别算法机器学习和模式识别有什么区别?看教材,发现它们的算法都差不多一样啊。。。网络电话永久免费打有没有永久免费的网络电话qq网络硬盘我QQ的网络硬盘怎么啦?单元测试规范求解,单片机程序的单元测试应该怎么做呢?什么是网络地址什么是IP地址?pmp格式有PMP格式转换成其他格式
淘宝虚拟主机 如何注册网站域名 高防dns softbank官网 wdcp 淘宝双十一2018 线路工具 tightvnc 镇江联通宽带 太原联通测速平台 web服务器架设 网络空间租赁 空间合租 七夕快乐英语 网购分享 贵阳电信测速 镇江高防 石家庄服务器 免费赚q币 香港ip 更多