org.springframework.test.context.support
Class AbstractGenericContextLoader

java.lang.Object
  extended by org.springframework.test.context.support.AbstractContextLoader
      extended by org.springframework.test.context.support.AbstractGenericContextLoader
All Implemented Interfaces:
ContextLoader
Direct Known Subclasses:
GenericPropertiesContextLoader, GenericXmlContextLoader

public abstract class AbstractGenericContextLoader
extends AbstractContextLoader

Abstract, generic extension of AbstractContextLoader which loads a GenericApplicationContext from the locations provided to loadContext(String...).

Concrete subclasses must provide an appropriate BeanDefinitionReader.

Since:
2.5
Author:
Sam Brannen, Juergen Hoeller
See Also:
loadContext(String...)

Field Summary
protected static Log logger
           
 
Constructor Summary
AbstractGenericContextLoader()
           
 
Method Summary
protected abstract  BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context)
          Factory method for creating new BeanDefinitionReaders for loading bean definitions into the supplied context.
protected  void customizeBeanFactory(DefaultListableBeanFactory beanFactory)
          Customize the internal bean factory of the ApplicationContext created by this ContextLoader.
protected  void customizeContext(GenericApplicationContext context)
          Customize the GenericApplicationContext created by this ContextLoader after bean definitions have been loaded into the context but before the context is refreshed.
 ConfigurableApplicationContext loadContext(String... locations)
          Loads a Spring ApplicationContext from the supplied locations.
protected  void prepareContext(GenericApplicationContext context)
          Prepare the GenericApplicationContext created by this ContextLoader.
 
Methods inherited from class org.springframework.test.context.support.AbstractContextLoader
generateDefaultLocations, getResourceSuffix, isGenerateDefaultLocations, modifyLocations, processLocations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final Log logger
Constructor Detail

AbstractGenericContextLoader

public AbstractGenericContextLoader()
Method Detail

loadContext

public final ConfigurableApplicationContext loadContext(String... locations)
                                                 throws Exception
Loads a Spring ApplicationContext from the supplied locations.

Implementation details:

Subclasses must provide an appropriate implementation of createBeanDefinitionReader(GenericApplicationContext).

Parameters:
locations - the resource locations to use to load the application context
Returns:
a new application context
Throws:
Exception - if context loading failed
See Also:
ContextLoader.loadContext(java.lang.String...), GenericApplicationContext, customizeBeanFactory(DefaultListableBeanFactory), createBeanDefinitionReader(GenericApplicationContext), BeanDefinitionReader

prepareContext

protected void prepareContext(GenericApplicationContext context)
Prepare the GenericApplicationContext created by this ContextLoader. Called before bean definitions are read.

The default implementation is empty. Can be overridden in subclasses to customize GenericApplicationContext's standard settings.

Parameters:
context - the context for which the BeanDefinitionReader should be created
See Also:
loadContext(java.lang.String...), GenericApplicationContext.setResourceLoader(org.springframework.core.io.ResourceLoader), GenericApplicationContext.setId(java.lang.String)

customizeBeanFactory

protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory)
Customize the internal bean factory of the ApplicationContext created by this ContextLoader.

The default implementation is empty but can be overridden in subclasses to customize DefaultListableBeanFactory's standard settings.

Parameters:
beanFactory - the bean factory created by this ContextLoader
See Also:
loadContext(java.lang.String...), DefaultListableBeanFactory.setAllowBeanDefinitionOverriding(boolean), DefaultListableBeanFactory.setAllowEagerClassLoading(boolean), AbstractAutowireCapableBeanFactory.setAllowCircularReferences(boolean), AbstractAutowireCapableBeanFactory.setAllowRawInjectionDespiteWrapping(boolean)

createBeanDefinitionReader

protected abstract BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context)
Factory method for creating new BeanDefinitionReaders for loading bean definitions into the supplied context.

Parameters:
context - the context for which the BeanDefinitionReader should be created
Returns:
a BeanDefinitionReader for the supplied context
See Also:
loadContext(java.lang.String...), BeanDefinitionReader

customizeContext

protected void customizeContext(GenericApplicationContext context)
Customize the GenericApplicationContext created by this ContextLoader after bean definitions have been loaded into the context but before the context is refreshed.

The default implementation is empty but can be overridden in subclasses to customize the application context.

Parameters:
context - the newly created application context
See Also:
loadContext(String...)