本文主要是介绍Spring之ContextLoaderListener,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Spring 官方文档
-
Spring Framework Documentation【Version 5.1.4.RELEASE】
-
ContextLoaderListener API Doc
介绍
web.xml中配置ContextLoaderListener,可以实例化ApplicationContext
You can register an ApplicationContext by using the ContextLoaderListener, as the following example shows:
<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>
</context-param><!-- Bootstrap the root application context as usual using ContextLoaderListener -->
<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
源码
package org.springframework.web.context;import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;public class ContextLoaderListener extends ContextLoader implements ServletContextListener {public ContextLoaderListener() {}public ContextLoaderListener(WebApplicationContext context) {super(context);}@Overridepublic void contextInitialized(ServletContextEvent event) {initWebApplicationContext(event.getServletContext());}@Overridepublic void contextDestroyed(ServletContextEvent event) {closeWebApplicationContext(event.getServletContext());ContextCleanupListener.cleanupAttributes(event.getServletContext());}}
这篇关于Spring之ContextLoaderListener的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!