/** * Register a {@link ContextLoaderListener} against the given servlet context. The {@code * ContextLoaderListener} is initialized with the application context returned from the {@link * #createRootApplicationContext()} template method. * * @param servletContext the servlet context to register the listener against */ protected void registerContextLoaderListener(ServletContext servletContext) { WebApplicationContext rootAppContext = createRootApplicationContext(); mylog.debug("创建WebApplicationContext,如果不为空并注册ContextLoaderListener"); if (rootAppContext != null) { ContextLoaderListener listener = new ContextLoaderListener(rootAppContext); listener.setContextInitializers(getRootApplicationContextInitializers()); servletContext.addListener(listener); } else { logger.debug( "No ContextLoaderListener registered, as " + "createRootApplicationContext() did not return an application context"); } }