001/*
002 * Copyright 2002-2012 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;
022
023/**
024 * Interface to provide configuration for a web application. This is read-only while
025 * the application is running, but may be reloaded if the implementation supports this.
026 *
027 * <p>This interface adds a {@code getServletContext()} method to the generic
028 * ApplicationContext interface, and defines a well-known application attribute name
029 * that the root context must be bound to in the bootstrap process.
030 *
031 * <p>Like generic application contexts, web application contexts are hierarchical.
032 * There is a single root context per application, while each servlet in the application
033 * (including a dispatcher servlet in the MVC framework) has its own child context.
034 *
035 * <p>In addition to standard application context lifecycle capabilities,
036 * WebApplicationContext implementations need to detect {@link ServletContextAware}
037 * beans and invoke the {@code setServletContext} method accordingly.
038 *
039 * @author Rod Johnson
040 * @author Juergen Hoeller
041 * @since January 19, 2001
042 * @see ServletContextAware#setServletContext
043 */
044public interface WebApplicationContext extends ApplicationContext {
045
046        /**
047         * Context attribute to bind root WebApplicationContext to on successful startup.
048         * <p>Note: If the startup of the root context fails, this attribute can contain
049         * an exception or error as value. Use WebApplicationContextUtils for convenient
050         * lookup of the root WebApplicationContext.
051         * @see org.springframework.web.context.support.WebApplicationContextUtils#getWebApplicationContext
052         * @see org.springframework.web.context.support.WebApplicationContextUtils#getRequiredWebApplicationContext
053         */
054        String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE = WebApplicationContext.class.getName() + ".ROOT";
055
056        /**
057         * Scope identifier for request scope: "request".
058         * Supported in addition to the standard scopes "singleton" and "prototype".
059         */
060        String SCOPE_REQUEST = "request";
061
062        /**
063         * Scope identifier for session scope: "session".
064         * Supported in addition to the standard scopes "singleton" and "prototype".
065         */
066        String SCOPE_SESSION = "session";
067
068        /**
069         * Scope identifier for global session scope: "globalSession".
070         * Supported in addition to the standard scopes "singleton" and "prototype".
071         */
072        String SCOPE_GLOBAL_SESSION = "globalSession";
073
074        /**
075         * Scope identifier for the global web application scope: "application".
076         * Supported in addition to the standard scopes "singleton" and "prototype".
077         */
078        String SCOPE_APPLICATION = "application";
079
080        /**
081         * Name of the ServletContext environment bean in the factory.
082         * @see javax.servlet.ServletContext
083         */
084        String SERVLET_CONTEXT_BEAN_NAME = "servletContext";
085
086        /**
087         * Name of the ServletContext/PortletContext init-params environment bean in the factory.
088         * <p>Note: Possibly merged with ServletConfig/PortletConfig parameters.
089         * ServletConfig parameters override ServletContext parameters of the same name.
090         * @see javax.servlet.ServletContext#getInitParameterNames()
091         * @see javax.servlet.ServletContext#getInitParameter(String)
092         * @see javax.servlet.ServletConfig#getInitParameterNames()
093         * @see javax.servlet.ServletConfig#getInitParameter(String)
094         */
095        String CONTEXT_PARAMETERS_BEAN_NAME = "contextParameters";
096
097        /**
098         * Name of the ServletContext/PortletContext attributes environment bean in the factory.
099         * @see javax.servlet.ServletContext#getAttributeNames()
100         * @see javax.servlet.ServletContext#getAttribute(String)
101         */
102        String CONTEXT_ATTRIBUTES_BEAN_NAME = "contextAttributes";
103
104
105        /**
106         * Return the standard Servlet API ServletContext for this application.
107         * <p>Also available for a Portlet application, in addition to the PortletContext.
108         */
109        ServletContext getServletContext();
110
111}