/param-value> org.springframework.web.context.ContextLoaderListener...我们研究一下ContextLoaderListener源码。 ContextLoaderListener继承自ContextLoader,实现的是ServletContextListener接口。...public class ContextLoaderListener extends ContextLoader implements ServletContextListener {...public ContextLoaderListener() {} public ContextLoaderListener(WebApplicationContext context) {...ContextLoaderListener的作用就是启动Web容器时,读取在contextConfigLocation中定义的xml文件,自动装配ApplicationContext的配置信息,并产生WebApplicationContext
一、web.xml 中经常有如下配置 org.springframework.web.context.ContextLoaderListener...context-param> contextConfigLocation 参数指定了spring启动要加载的配置文件,如果不指定,Spring 会加载WEB-INF目录下applicationContext.xml 二、ContextLoaderListener...分析 ContextLoaderListener类图 可以看到 ContextLoaderListener实现了ServletContextListener接口,继承了ContextLoader...ContextLoaderListener实现了ServletContextListener的接口方法:contextInitialized和contextDestroyed 方法分别调用了 ContextLoader
3 private ContextLoader contextLoader; 4 5 6 /** 7 * Create a new {@code ContextLoaderListener...* default values for each. 11 * This constructor is typically used when declaring {@code ContextLoaderListener...* lifecycle method is invoked on this listener. 18 * @see ContextLoader 19 * @see #ContextLoaderListener...() { 24 } 25 26 /** 27 * Create a new {@code ContextLoaderListener} with the given...另外从上面的一些注释我们可以看出: WEB-INF/applicationContext.xml, 如果我们项目中的配置文件不是这么一个路径的话 那么我们使用ContextLoaderListener
listenerStart 严重: Error configuring application listener of class [org.springframework.web.context.ContextLoaderListener...] java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener at org.apache.catalina.loader.WebappClassLoaderBase.loadClass
SSM开发网上一找一大堆,可是有时候深入使用一下问题还不少,今天就来看看ContextLoaderListener配置带来的问题。...首先我们得知道,tomcat启动后首先会实例化初始化ContextLoaderListener,创建出一个上下文容器。...google一下,查到了这篇问答[ContextLoaderListener or not?...翻译如下: 如果只使用servlet的上下文就可以正常工作,没有理由保留ContextLoaderListener。...在web开发中,普遍鼓励在ContextLoaderListener的上下文中保留非web内容,但它只不过是一个小小的建议。
对于熟悉Spring MVC功能,首先应从web.xml 开始,在web.xml 文件中我们需要配置一个监听器 ContextLoaderListener,如下。 <param-name...ContextLoaderListener 源码分析 public class ContextLoaderListener extends ContextLoader implements ServletContextListener...{ public ContextLoaderListener() { } public ContextLoaderListener(WebApplicationContext...总结 通过代码分析ContextLoaderListener的作用就是启动Web容器的时候,初始化WebApplicationContext实例,并存放到ServletContext中。
今天说一说ContextLoaderListener和ContextConfigLocation详解「建议收藏」,希望能够帮助大家进步!!!...ContextLoaderListener 在Spring中ContextLoaderListener实现了ServletContentListener类,该类可以作为Listener使用。...contextConfigLocation classpath:applicationContext.xml ContextLoaderListener
ContextLoaderListener 作为一个Listener会首先启动,创建一个WebApplicationContext用于加载除Controller等Web组件以外的所有bean,这个ApplicationContext...web.xml配置 ContextLoaderListener监听器的作用就是启动web容器时,自动装配ApplicationContext的配置信息。...-- Spring监听器 --> org.springframework.web.context.ContextLoaderListener...</listener- class> 通过扩展ContextLoaderListener类,可以增加初始化时的个性化功能,如输出产品的信息等。
发现启动报下面这个错误,如下所示: 1 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener...2 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 此时,可能是由于项目没有加载
SSH项目的时候出现了如下错误: 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener...java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 网上查了一下,有些人说是没有...双击web.xml的“org.springframework.web.context.ContextLoaderListener”也能跳转到对应class文件里面。显然并不是缺少包的原因。
Spring Security 的OAuth是遇到了一个错误: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener...注册 ContextLoaderListener 修改web.xml如下 org.springframework.web.context.ContextLoaderListener... 注意,如果使用了Log4jConfigListener,需要把ContextLoaderListener放在后面。
二、ContextLoaderListener扩展接口 ContextLoaderListener一般用来启动一个Spring容器或者框架的根容器,例如Webx框架的WebxContextLoaderListener...就是继承该类,实现了webx框架到Tomcat容器的衔接点,而SpringMVC则通过在ContextLoaderListener启动一个IOC来管理bo类的bean,下面首先看下ContextLoaderListener...可知ContextLoaderListener的两个方法都是含有一个ServletContextEvent类型的参数。 那么这个ContextLoaderListener一般是怎么使用的那?...ContextLoaderListener一般是按照下面的方式配置到web.xml里面: ?...ContextLoaderListener与Tomcat是什么关系那?ContextLoaderListener是如何创建的XmlWebApplicationContext?
问题分析 问题就出在ContextLoaderListener和DispatcherServlet,他们都可以引入spring,而且每个引入都会实例化一次bean。...但是,当我们使用Spring Bean的时候,只会用到DispatcherServlet下的Bean,而不会用到ContextLoaderListener下的Bean,这就会导致ContextLoaderListener...使用ContextLoaderlistener和DispatcherServlet引入Spring的区别 ContextLoaderListener和DispatcherServlet都会生成一个WebApplicationContext...同一个容器里,只允许有一个ContextLoaderListener但是可以用多个DispatcherServlet。...DispatcherServlet的context总是ContextLoaderListener的context的子类。
Spring和Web容器分两个步骤: 1、导入spring-web-4.0.0.RELEASE.jar 2、在web.xml配置文件中配置org.springframework.web.context.ContextLoaderListener...-- needed for ContextLoaderListener --> org.springframework.web.context.ContextLoaderListener</listener-class...我们可以深入进去看看底层源码: public class ContextLoaderListener extends ContextLoader implements ServletContextListener...--> org.springframework.web.context.ContextLoaderListener
其中DispatcherServlet是一个Servlet,具备Servlet的生命周期,ContextLoaderListener实现了ServletContextListener接口,该接口提供了关于...{ public ContextLoaderListener() { } public ContextLoaderListener(WebApplicationContext... ContextLoaderListener监听器默认读取/WEB-INF/下的applicationContext.xml文件。...如下图: 对于作用范围而言,在DispatcherServlet中可以引用由ContextLoaderListener所创建的ApplicationContext中的内容,而反过来不行。...这也解释了为什么我们可以在DispatcherServlet中获取到由ContextLoaderListener对应的ApplicationContext中的bean。
首先我们来看下 ContextLoaderListener 监听器的源码: ?...因此,ContextLoaderListener 最主要的作用就是在 Tomcat 启动时,根据配置加载 Spring 容器。 ?...以上就是 ContextLoaderListener 实现 contextInitialized 方法的逻辑,也是加载并初始化 Spring 容器的开始。...我们发现,rootContext 就是 ContextLoaderListener 加载的 Spring 容器,在这里,它会以父容器的身份保存到 SpringMVC 容器中。...同时将上文所说的 ContextLoaderListener 监听器添加到 Servlet 容器中,同样达到了 xml 配置的效果,而调用 createRootApplicationContext 方法创建
Spring提供获取应用上下文的工具 上面的分析不用手动实现,Spring提供了一个监听器ContextLoaderListener就是对上述功能的封装,该监听器内部加载Spring配置文件,创建应用上下文对象...所以我们需要做的只有两件事: 1、在web.xml中配置ContextLoaderListener监听器(导入spring-web坐标) 2、使用WebApplicationContextUtils获得应用上下文对象...org.springframework spring-web 5.3.10 配置ContextLoaderListener...--配置Spring的监听器--> org.springframework.web.context.ContextLoaderListener</
listener> spring监听器 org.springframework.web.context.ContextLoaderListener...ContextLoderListener实现了ServletContextListener,所以最先执行初始化方法contextInitianized进行初始化 initWebApplicationContext 通过对ContextLoaderListener...的源码分析,我们看到ContextLoaderListener继承ContextLoader,所以ContextLoaderListener本身也是Spring的上下文加载器。...ContextLoaderListener实现了ServletContextListener接口,当Web应用在Web服务器中被被启动和停止时,Web服务器启动和停止事件会分别触发ContextLoaderListener...我们通过上述对ContextLoaderListener的源码分析看到真正实现Spring上下文的初始化和销毁功能的是ContextLoader类 public class ContextLoaderListener
(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java...servlet-mapping> org.springframework.web.context.ContextLoaderListener... 后来慢慢的发现这个情况出现在为org.springframework.web.context.ContextLoaderListener...二、 查看下代码看看是怎么回事 首先定位到ContextLoaderListener#contextInitialized方法 /** public void contextInitialized...看了下ContextLoaderListener的代码流程终于明白了,原来ContextLoaderListener要启动spring,需要得到配置文件的路径contextConfigLocation,
领取专属 10元无门槛券
手把手带您无忧上云