Package org.springframework.web.context.support

# Class ServletContextScope

java.lang.Object
org.springframework.web.context.support.ServletContextScope

All Implemented Interfaces:
  `org.springframework.beans.factory.config.Scope`, `org.springframework.beans.factory.DisposableBean`

public class ServletContextScope extends Object implements org.springframework.beans.factory.config.Scope, org.springframework.beans.factory.DisposableBean
`Scope` wrapper for a ServletContext, i.e. for global web application attributes.

This differs from traditional Spring singletons in that it exposes attributes in the ServletContext. Those attributes will get destroyed whenever the entire application shuts down, which might be earlier or later than the shutdown of the containing Spring ApplicationContext.

The associated destruction mechanism relies on a `ContextCleanupListener` being registered in `web.xml`. Note that `ContextLoaderListener` includes ContextCleanupListener's functionality.

This scope is registered as default scope with key `"application"`.

Since:
  3.0
Author:
  Juergen Hoeller
See Also:
  - `ContextCleanupListener`

## Constructor Summary

Constructors
Constructor
Description
`ServletContextScope(ServletContext servletContext)`
Create a new Scope wrapper for the given ServletContext.

## Method Summary

Modifier and Type
Method
Description
`void`
`destroy()`
Invoke all registered destruction callbacks.
`Object`
`get(String name, org.springframework.beans.factory.ObjectFactory<?> objectFactory)`
`String`
`getConversationId()`
`void`
`registerDestructionCallback(String name, Runnable callback)`
`Object`
`remove(String name)`
`Object`
`resolveContextualObject(String key)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ServletContextScope

public ServletContextScope(ServletContext servletContext)
Create a new Scope wrapper for the given ServletContext.

Parameters:
  `servletContext` - the ServletContext to wrap

## Method Details

### get

public Object get(String name, org.springframework.beans.factory.ObjectFactory<?> objectFactory)

Specified by:
  `get` in interface `org.springframework.beans.factory.config.Scope`

### remove

@Nullable public Object remove(String name)

Specified by:
  `remove` in interface `org.springframework.beans.factory.config.Scope`

### registerDestructionCallback

public void registerDestructionCallback(String name, Runnable callback)

Specified by:
  `registerDestructionCallback` in interface `org.springframework.beans.factory.config.Scope`

### resolveContextualObject

@Nullable public Object resolveContextualObject(String key)

Specified by:
  `resolveContextualObject` in interface `org.springframework.beans.factory.config.Scope`

### getConversationId

@Nullable public String getConversationId()

Specified by:
  `getConversationId` in interface `org.springframework.beans.factory.config.Scope`

### destroy

public void destroy()
Invoke all registered destruction callbacks. To be called on ServletContext shutdown.

Specified by:
  `destroy` in interface `org.springframework.beans.factory.DisposableBean`
See Also:
  - `ContextCleanupListener`