Package org.springframework.web.context.support

# Class ServletContextAttributeFactoryBean

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

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.FactoryBean<Object>`, `ServletContextAware`

public class ServletContextAttributeFactoryBean extends Object implements org.springframework.beans.factory.FactoryBean<Object>, ServletContextAware
`FactoryBean` that fetches a specific, existing ServletContext attribute. Exposes that ServletContext attribute when used as bean reference, effectively making it available as named Spring bean instance.

Intended to link in ServletContext attributes that exist before the startup of the Spring application context. Typically, such attributes will have been put there by third-party web frameworks. In a purely Spring-based web application, no such linking in of ServletContext attributes will be necessary.

NOTE: You may also use the "contextAttributes" default bean, which is of type Map, and dereference it using a "#{contextAttributes.myKey}" expression to access a specific attribute by name.

Since:
  1.1.4
Author:
  Juergen Hoeller
See Also:
  - `WebApplicationContext.CONTEXT_ATTRIBUTES_BEAN_NAME`
  - `ServletContextParameterFactoryBean`

## Field Summary

### Fields inherited from interface org.springframework.beans.factory.FactoryBean

`OBJECT_TYPE_ATTRIBUTE`

## Constructor Summary

Constructors
Constructor
Description
`ServletContextAttributeFactoryBean()`

## Method Summary

Modifier and Type
Method
Description
`Object`
`getObject()`
`Class<?>`
`getObjectType()`
`boolean`
`isSingleton()`
`void`
`setAttributeName(String attributeName)`
Set the name of the ServletContext attribute to expose.
`void`
`setServletContext(ServletContext servletContext)`
Set the `ServletContext` that this object runs in.

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

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

## Constructor Details

### ServletContextAttributeFactoryBean

public ServletContextAttributeFactoryBean()

## Method Details

### setAttributeName

public void setAttributeName(String attributeName)
Set the name of the ServletContext attribute to expose.

### setServletContext

public void setServletContext(ServletContext servletContext)
Description copied from interface: `ServletContextAware`
Set the `ServletContext` that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's `afterPropertiesSet` or a custom init-method. Invoked after ApplicationContextAware's `setApplicationContext`.

Specified by:
  `setServletContext` in interface `ServletContextAware`
Parameters:
  `servletContext` - the ServletContext object to be used by this object
See Also:
  - `InitializingBean.afterPropertiesSet()`
  - `ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)`

### getObject

@Nullable public Object getObject() throws Exception

Specified by:
  `getObject` in interface `org.springframework.beans.factory.FactoryBean<Object>`
Throws:
  `Exception`

### getObjectType

@Nullable public Class<?> getObjectType()

Specified by:
  `getObjectType` in interface `org.springframework.beans.factory.FactoryBean<Object>`

### isSingleton

public boolean isSingleton()

Specified by:
  `isSingleton` in interface `org.springframework.beans.factory.FactoryBean<Object>`