001/* 002 * Copyright 2002-2016 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.context; 018 019import javax.servlet.ServletContext; 020 021import org.springframework.context.ApplicationContext; 022import org.springframework.lang.Nullable; 023 024/** 025 * Interface to provide configuration for a web application. This is read-only while 026 * the application is running, but may be reloaded if the implementation supports this. 027 * 028 * <p>This interface adds a {@code getServletContext()} method to the generic 029 * ApplicationContext interface, and defines a well-known application attribute name 030 * that the root context must be bound to in the bootstrap process. 031 * 032 * <p>Like generic application contexts, web application contexts are hierarchical. 033 * There is a single root context per application, while each servlet in the application 034 * (including a dispatcher servlet in the MVC framework) has its own child context. 035 * 036 * <p>In addition to standard application context lifecycle capabilities, 037 * WebApplicationContext implementations need to detect {@link ServletContextAware} 038 * beans and invoke the {@code setServletContext} method accordingly. 039 * 040 * @author Rod Johnson 041 * @author Juergen Hoeller 042 * @since January 19, 2001 043 * @see ServletContextAware#setServletContext 044 */ 045public interface WebApplicationContext extends ApplicationContext { 046 047 /** 048 * Context attribute to bind root WebApplicationContext to on successful startup. 049 * <p>Note: If the startup of the root context fails, this attribute can contain 050 * an exception or error as value. Use WebApplicationContextUtils for convenient 051 * lookup of the root WebApplicationContext. 052 * @see org.springframework.web.context.support.WebApplicationContextUtils#getWebApplicationContext 053 * @see org.springframework.web.context.support.WebApplicationContextUtils#getRequiredWebApplicationContext 054 */ 055 String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE = WebApplicationContext.class.getName() + ".ROOT"; 056 057 /** 058 * Scope identifier for request scope: "request". 059 * Supported in addition to the standard scopes "singleton" and "prototype". 060 */ 061 String SCOPE_REQUEST = "request"; 062 063 /** 064 * Scope identifier for session scope: "session". 065 * Supported in addition to the standard scopes "singleton" and "prototype". 066 */ 067 String SCOPE_SESSION = "session"; 068 069 /** 070 * Scope identifier for the global web application scope: "application". 071 * Supported in addition to the standard scopes "singleton" and "prototype". 072 */ 073 String SCOPE_APPLICATION = "application"; 074 075 /** 076 * Name of the ServletContext environment bean in the factory. 077 * @see javax.servlet.ServletContext 078 */ 079 String SERVLET_CONTEXT_BEAN_NAME = "servletContext"; 080 081 /** 082 * Name of the ServletContext init-params environment bean in the factory. 083 * <p>Note: Possibly merged with ServletConfig parameters. 084 * ServletConfig parameters override ServletContext parameters of the same name. 085 * @see javax.servlet.ServletContext#getInitParameterNames() 086 * @see javax.servlet.ServletContext#getInitParameter(String) 087 * @see javax.servlet.ServletConfig#getInitParameterNames() 088 * @see javax.servlet.ServletConfig#getInitParameter(String) 089 */ 090 String CONTEXT_PARAMETERS_BEAN_NAME = "contextParameters"; 091 092 /** 093 * Name of the ServletContext attributes environment bean in the factory. 094 * @see javax.servlet.ServletContext#getAttributeNames() 095 * @see javax.servlet.ServletContext#getAttribute(String) 096 */ 097 String CONTEXT_ATTRIBUTES_BEAN_NAME = "contextAttributes"; 098 099 100 /** 101 * Return the standard Servlet API ServletContext for this application. 102 */ 103 @Nullable 104 ServletContext getServletContext(); 105 106}