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

亚洲云-浙江高防BGP,至强铂金8270,提供自助防火墙管理,超大内存满足你各种需求

官方网站:点击访问亚洲云官网618活动方案:618特价活动(6.18-6.30)全站首月活动月底结束!地区:浙江高防BGPCPU:至强铂金8270主频7 默频3.61 睿频4.0核心:8核(最高支持64核)内存:8G(最高支持128G)DDR4 3200硬盘:40G系统盘+80G数据盘带宽:上行:20Mbps/下行:1000Mbps防御:100G(可加至300G)防火墙:提供自助 天机盾+金盾 管...

提速啦(900元/月),杭州BGP E5-2665/89*2 32核 48G 100G防御

提速啦的来历提速啦是 网站 本着“良心 便宜 稳定”的初衷 为小白用户避免被坑提速啦的市场定位提速啦主要代理市场稳定速度的云服务器产品,避免新手购买云服务器的时候众多商家不知道如何选择,妮妮云就帮你选择好了产品,无需承担购买风险,不用担心出现被跑路 被诈骗的情况。提速啦的售后保证提速啦退款 通过于合作商的友好协商,云服务器提供3天内全额退款,超过3天不退款 物理机部分支持当天全额退款提速啦提现 充...

hostkey俄罗斯、荷兰GPU显卡服务器/免费Windows Server

Hostkey.com成立于2007年的荷兰公司,主要运营服务器出租与托管,其次是VPS、域名、域名证书,各种软件授权等。hostkey当前运作荷兰阿姆斯特丹、俄罗斯莫斯科、美国纽约等数据中心。支持Paypal,信用卡,Webmoney,以及支付宝等付款方式。禁止VPN,代理,Tor,网络诈骗,儿童色情,Spam,网络扫描,俄罗斯色情,俄罗斯电影,俄罗斯MP3,俄罗斯Trackers,以及俄罗斯法...

contextloaderlistener为你推荐
换脸软件手机上哪个软件可以换脸?就是P金馆长那种脸 美化照片的就不要说了应用雷达雷达是干什么用的?知识分享平台微信看到一些文章,可以分享到知识付费的平台吗?怎么操作呀?orphanremoval大家知道orphan这个单词除了孤儿还有什么意思吗?y码衣服的尺码标识,3xL xL xxL都代表的什么意思?qq博客怎么开QQ博客啊!qq博客怎样开通QQ博客?assemblyinfoasp.net这几个文件是干什么的?遗传算法实例如何用C语言实现遗传算法的实际应用?腾讯技术腾讯是什么东西?
godaddy域名注册 godaddy域名解析教程 域名停靠一青草视频 淘宝二级域名 免费申请域名 线路工具 华为网络硬盘 gspeed 已备案删除域名 双十一秒杀 多线空间 卡巴斯基免费试用版 免费asp空间 云服务器比较 空间服务器 asp空间 wordpress空间 湖南铁通 优惠服务器 asp简介 更多