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

#推荐# cmivps:全场7折,香港不限流量VPS,支持Windows系统

cmivps香港VPS带来了3个新消息:(1)双向流量改为单向流量,相当于流量间接扩大一倍;(2)Hong Kong 2T、Hong Kong 3T、Hong Kong 无限流量,这三款VPS开始支持Windows系统,如果需要中文版Windows系统请下单付款完成之后发ticket要求官方更改即可;(3)全场7折年付、8折月付优惠,优惠码有效期一个月!官方网站:https://www.cmivp...

#消息# contabo:德国老牌机房新增美国“纽约、西雅图”数据中心,免设置费

运作了18年的德国老牌机房contabo在继去年4月开办了第一个美国数据中心(中部城市:圣路易斯)后立马在本月全新上马两个数据中心:纽约、西雅图。当前,为庆祝美国独立日,美国三个数据中心的VPS全部免除设置费,VPS本身的配置很高,价格适中,有较高的性价比!官方网站:https://contabo.com/en/SSD VPSKVM虚拟,纯SSD阵列,不限制流量,自带一个IPv4内存CPUSSD带...

Hostinger 限时外贸美国主机活动 低至月12元且赠送1个COM域名

Hostinger 商家我们可能一些新用户不是太熟悉,因为我们很多新人用户都可能较多的直接从云服务器、独立服务器起步的。而Hostinger商家已经有将近十年的历史的商家,曾经主做低价虚拟主机,也是比较有知名度的,那时候也有接触过,不过一直没有过多的使用。这不这么多年过去,Hostinger商家一直比较稳妥的在运营,最近看到这个商家在改版UI后且产品上也在活动策划比较多。目前Hostinger在进...

contextloaderlistener为你推荐
企业资源管理系统企业管理系统都有什么功能orphanremovalorphan是什么意思扫图高清扫图是什么意思,在很多的贴吧里,都有提到一些高清扫图,是自己照杂志上的图片,然后自己再修一下吗awv如何把普通电影转换成AWV模式识别算法研究生研究方向:数据挖掘、模式识别、启发算法这三者哪个有前途天翼校园宽带天翼校园宽带 是怎么算时间的 一个月 是指从办理那天开始 往后 30天是一个月吗 还是 办理的那天所在的那个超级播放器推荐个好的视频播放器kjavaJava与KJava有什么区别吗.?河北云办税厅河北省商务厅的人员编制上传图片网站求一个可以上传图片外链的网站
域名论坛 传奇服务器租用 php主机 godaddy域名证书 我爱水煮鱼 linux空间 idc是什么 域名评估 空间合租 1美金 绍兴电信 支付宝扫码领红包 服务器硬件防火墙 net空间 东莞服务器托管 个人免费邮箱 网页加速 xuni 网站加速 hdchina 更多