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

HostKvm:夏季优惠,香港云地/韩国vps终身7折,线路好/机器稳/适合做站

hostkvm怎么样?hostkvm是一家国内老牌主机商家,商家主要销售KVM架构的VPS,目前有美国、日本、韩国、中国香港等地的服务,站长目前还持有他家香港CN2线路的套餐,已经用了一年多了,除了前段时间香港被整段攻击以外,一直非常稳定,是做站的不二选择,目前商家针对香港云地和韩国机房的套餐进行7折优惠,其他套餐为8折,商家支持paypal和支付宝付款。点击进入:hostkvm官方网站地址hos...

CYUN(29元/月)美国、香港、台湾、日本、韩国CN2,续费原价

关于CYUN商家在之前有介绍过一次,CYUN是香港蓝米数据有限公司旗下的云计算服务品牌,和蓝米云、蓝米主机等同属该公司。商家主要是为个人开发者用户、中小型、大型企业用户提供一站式核心网络云端部署服务,促使用户云端部署化简为零,轻松快捷运用云计算。目前,CYUN主要运营美国、香港、台湾、日本、韩国CN2线路产品,包括云服务器、站群服务器和独立服务器等。这次看到CYUN夏季优惠活动发布了,依然是熟悉的...

MechanicWeb免费DirectAdmin/异地备份

MechanicWeb怎么样?MechanicWeb好不好?MechanicWeb成立于2008年,目前在美国洛杉矶、凤凰城、达拉斯、迈阿密、北卡、纽约、英国、卢森堡、德国、加拿大、新加坡有11个数据中心,主营全托管型虚拟主机、VPS主机、半专用服务器和独立服务器业务。MechanicWeb只做高端的托管vps,这次MechanicWeb上新Xeon W-1290P处理器套餐,基准3.7GHz最高...

contextloaderlistener为你推荐
知识分享平台关于分享职场技能的知识付费平台,大家有什么好推荐的吗?chrome系统Chromenbsp;OS是操作系统吗?chrome系统Chrome OS是什么系统?chrome系统谷歌Chrome OS可以用来做什么?labelforhtml中label是什么意思啊?河北云办税厅用小度怎么打开河北教育资讯云平台?电子邮件软件电子邮件软件哪个好用免费下载空间怎么下载免费的空间播放器免费下载空间要下载免费空间播放器怎么弄pmp格式PMP的格式
中文域名 星星海 美国主机评测 紫田 搜狗抢票助手 免费静态空间 长沙服务器 蜗牛魔方 193邮箱 vip购优汇 上海电信测速 德隆中文网 qq金券 免费蓝钻 广州主机托管 免费赚q币 register.com cx域名 美国vpn代理 ubuntu安装教程 更多