Top Description Fields Constructors Methods
org.springframework.web.context.support

public Class GroovyWebApplicationContext

extends AbstractRefreshableWebApplicationContext
implements GroovyObject
Class Inheritance
All Implemented Interfaces
groovy.lang.GroovyObject
Imports
java.io.IOException, groovy.lang.GroovyObject, .GroovySystem, .MetaClass, org.springframework.beans.BeanWrapper, .BeanWrapperImpl, .BeansException, org.springframework.beans.factory.NoSuchBeanDefinitionException, org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader, org.springframework.beans.factory.support.DefaultListableBeanFactory, org.springframework.lang.Nullable

Deprecated

as a consequence of AbstractRefreshableWebApplicationContext being deprecated. See corresponding docs for further information.

org.springframework.web.context.WebApplicationContext implementation which takes its configuration from Groovy bean definition scripts and/or XML files, as understood by a org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader. This is essentially the equivalent of org.springframework.context.support.GenericGroovyApplicationContext for a web environment.

By default, the configuration will be taken from "/WEB-INF/applicationContext.groovy" for the root context, and "/WEB-INF/test-servlet.groovy" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").

The config location defaults can be overridden via the "contextConfigLocation" context-param of org.springframework.web.context.ContextLoader and servlet init-param of org.springframework.web.servlet.FrameworkServlet. Config locations can either denote concrete files like "/WEB-INF/context.groovy" or Ant-style patterns like "/WEB-INF/*-context.groovy" (see org.springframework.util.PathMatcher javadoc for pattern details). Note that ".xml" files will be parsed as XML content; all other kinds of resources will be parsed as Groovy scripts.

Note

In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra Groovy script.

For a WebApplicationContext that reads in a different bean definition format, create an analogous subclass of AbstractRefreshableWebApplicationContext. Such a context implementation can be specified as "contextClass" context-param for ContextLoader or "contextClass" init-param for FrameworkServlet.

Author
Juergen Hoeller
Since
4.1
See Also
setNamespace, setConfigLocations, org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader, org.springframework.web.context.ContextLoader#initWebApplicationContext, org.springframework.web.servlet.FrameworkServlet#initWebApplicationContext

Field Summary

Modifier and TypeField and Description
private final BeanWrapper
public static final String
DEFAULT_CONFIG_LOCATION

Default config location for the root context.

public static final String
DEFAULT_CONFIG_LOCATION_PREFIX

Default prefix for building a config location for a namespace.

public static final String
DEFAULT_CONFIG_LOCATION_SUFFIX

Default suffix for building a config location for a namespace.

private MetaClass

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected String[]
getDefaultConfigLocations()

Overrides org.springframework.context.support.AbstractRefreshableConfigApplicationContext.getDefaultConfigLocations.

The default location for the root context is "/WEB-INF/applicationContext.groovy", and "/WEB-INF/test-servlet.groovy" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").
public MetaClass
getMetaClass()

Implements groovy.lang.GroovyObject.getMetaClass.

Returns the metaclass for a given class.
public Object
getProperty(String
the name of the property of interest
property
)

Overrides default groovy.lang.GroovyObject.getProperty.

Retrieves a property value.
protected void
initBeanDefinitionReader(GroovyBeanDefinitionReader
the bean definition reader used by this context
beanDefinitionReader
)

Initialize the bean definition reader used for loading the bean definitions of this context.

public Object
invokeMethod(String
the name of the method to call
name
,
Object
the arguments to use for the method call
args
)

Overrides default groovy.lang.GroovyObject.invokeMethod.

Invokes the given method.
protected void
loadBeanDefinitions(DefaultListableBeanFactory
the bean factory to load bean definitions into
beanFactory
)

Implements abstract org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

Loads the bean definitions via an GroovyBeanDefinitionReader.
protected void
loadBeanDefinitions(GroovyBeanDefinitionReader reader)

Load the bean definitions with the given GroovyBeanDefinitionReader.

public void
setMetaClass(MetaClass
the new metaclass
metaClass
)

Implements groovy.lang.GroovyObject.setMetaClass.

Allows the MetaClass to be replaced with a derived implementation.
public void
setProperty(String
the name of the property of interest
property
,
Object
the new value for the property
newValue
)

Overrides default groovy.lang.GroovyObject.setProperty.

Sets the given property to the new value.
Inherited from org.springframework.web.context.support.AbstractRefreshableWebApplicationContext:
createEnvironmentgetApplicationNamegetConfigLocationsgetNamespacegetResourceByPathgetResourcePatternResolvergetServletConfiggetServletContextgetThemeinitPropertySourcesonRefreshpostProcessBeanFactorysetNamespacesetServletConfigsetServletContext

Field Detail

contextWrapperback to summary
private final BeanWrapper contextWrapper
DEFAULT_CONFIG_LOCATIONback to summary
public static final String DEFAULT_CONFIG_LOCATION

Default config location for the root context.

DEFAULT_CONFIG_LOCATION_PREFIXback to summary
public static final String DEFAULT_CONFIG_LOCATION_PREFIX

Default prefix for building a config location for a namespace.

DEFAULT_CONFIG_LOCATION_SUFFIXback to summary
public static final String DEFAULT_CONFIG_LOCATION_SUFFIX

Default suffix for building a config location for a namespace.

metaClassback to summary
private MetaClass metaClass

Constructor Detail

GroovyWebApplicationContextback to summary
public GroovyWebApplicationContext()

Method Detail

getDefaultConfigLocationsback to summary
protected String[] getDefaultConfigLocations()

Overrides org.springframework.context.support.AbstractRefreshableConfigApplicationContext.getDefaultConfigLocations.

The default location for the root context is "/WEB-INF/applicationContext.groovy", and "/WEB-INF/test-servlet.groovy" for a context with the namespace "test-servlet" (like for a DispatcherServlet instance with the servlet-name "test").

Returns:String[]

Doc from org.springframework.context.support.AbstractRefreshableConfigApplicationContext.getDefaultConfigLocations.

an array of default config locations, if any

Annotations
@Override
getMetaClassback to summary
public MetaClass getMetaClass()

Implements groovy.lang.GroovyObject.getMetaClass.

Doc from groovy.lang.GroovyObject.getMetaClass.

Returns the metaclass for a given class.

Returns:MetaClass

the metaClass of this instance

Annotations
@Override
getPropertyback to summary
public Object getProperty(String property)

Overrides default groovy.lang.GroovyObject.getProperty.

Doc from groovy.lang.GroovyObject.getProperty.

Retrieves a property value.

Parameters
property:String

the name of the property of interest

Returns:Object

the given property

Annotations
@Override
@Nullable
initBeanDefinitionReaderback to summary
protected void initBeanDefinitionReader(GroovyBeanDefinitionReader beanDefinitionReader)

Initialize the bean definition reader used for loading the bean definitions of this context. Default implementation is empty.

Can be overridden in subclasses.

Parameters
beanDefinitionReader:GroovyBeanDefinitionReader

the bean definition reader used by this context

invokeMethodback to summary
public Object invokeMethod(String name, Object args)

Overrides default groovy.lang.GroovyObject.invokeMethod.

Doc from groovy.lang.GroovyObject.invokeMethod.

Invokes the given method.

Parameters
name:String

the name of the method to call

args:Object

the arguments to use for the method call

Returns:Object

the result of invoking the method

Annotations
@Override
loadBeanDefinitionsback to summary
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException

Implements abstract org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

Loads the bean definitions via an GroovyBeanDefinitionReader.

Parameters
beanFactory:DefaultListableBeanFactory

Doc from org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

the bean factory to load bean definitions into

Annotations
@Override
Exceptions
BeansException:

Doc from org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

if parsing of the bean definitions failed

IOException:

Doc from org.springframework.context.support.AbstractRefreshableApplicationContext.loadBeanDefinitions.

if loading of bean definition files failed

See Also
org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader, initBeanDefinitionReader, loadBeanDefinitions
loadBeanDefinitionsback to summary
protected void loadBeanDefinitions(GroovyBeanDefinitionReader reader) throws IOException

Load the bean definitions with the given GroovyBeanDefinitionReader.

The lifecycle of the bean factory is handled by the refreshBeanFactory method; therefore this method is just supposed to load and/or register bean definitions.

Delegates to a ResourcePatternResolver for resolving location patterns into Resource instances.

Exceptions
IOException:
if the required Groovy script or XML file isn't found
See Also
refreshBeanFactory, getConfigLocations, getResources, getResourcePatternResolver
setMetaClassback to summary
public void setMetaClass(MetaClass metaClass)

Implements groovy.lang.GroovyObject.setMetaClass.

Doc from groovy.lang.GroovyObject.setMetaClass.

Allows the MetaClass to be replaced with a derived implementation.

Parameters
metaClass:MetaClass

the new metaclass

Annotations
@Override
setPropertyback to summary
public void setProperty(String property, Object newValue)

Overrides default groovy.lang.GroovyObject.setProperty.

Doc from groovy.lang.GroovyObject.setProperty.

Sets the given property to the new value.

Parameters
property:String

the name of the property of interest

newValue:Object

the new value for the property

Annotations
@Override