spring-web

org.springframework.web.context.support
Class ServletContextAttributeFactoryBean

java.lang.Object
  extended by org.springframework.web.context.support.ServletContextAttributeFactoryBean
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.FactoryBean<java.lang.Object>, ServletContextAware

public class ServletContextAttributeFactoryBean
extends java.lang.Object
implements org.springframework.beans.factory.FactoryBean<java.lang.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: As of Spring 3.0, you may also use the "contextAttributes" default bean which is of type Map, and dereference it using an "#{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

Constructor Summary
ServletContextAttributeFactoryBean()
           
 
Method Summary
 java.lang.Object getObject()
           
 java.lang.Class<?> getObjectType()
           
 boolean isSingleton()
           
 void setAttributeName(java.lang.String attributeName)
          Set the name of the ServletContext attribute to expose.
 void setServletContext(javax.servlet.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 Detail

ServletContextAttributeFactoryBean

public ServletContextAttributeFactoryBean()
Method Detail

setAttributeName

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


setServletContext

public void setServletContext(javax.servlet.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 - ServletContext object to be used by this object
See Also:
InitializingBean.afterPropertiesSet(), ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)

getObject

public java.lang.Object getObject()
                           throws java.lang.Exception
Specified by:
getObject in interface org.springframework.beans.factory.FactoryBean<java.lang.Object>
Throws:
java.lang.Exception

getObjectType

public java.lang.Class<?> getObjectType()
Specified by:
getObjectType in interface org.springframework.beans.factory.FactoryBean<java.lang.Object>

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface org.springframework.beans.factory.FactoryBean<java.lang.Object>

spring-web