Class JavaConfigContextLoader

  extended by
All Implemented Interfaces:

public class JavaConfigContextLoader
extends java.lang.Object
implements org.springframework.test.context.ContextLoader

Implementation of the ContextLoader strategy for creating a JavaConfigApplicationContext for a test's @ContextConfiguration

Example usage:

 @ContextConfiguration(locations = {"com.myco.TestDatabaseConfiguration", "com.myco.config"},
                       loader = JavaConfigContextLoader.class)
 public MyTests { ... }

Implementation note: At this time, due to restrictions in Java annotations and Spring's TestContext framework, locations of classes / packages must be specified as strings to the ContextConfiguration annotation. It is understood that this has a detrimental effect on type safety, discoverability and refactoring, and for these reasons may change in future revisions, possibly with a customized version of the ContextConfiguration annotation that accepts an array of class literals to load.

Jim Moore, Chris Beams
See Also:

Field Summary
protected  org.apache.commons.logging.Log logger
Constructor Summary
Method Summary
 org.springframework.context.ApplicationContext loadContext(java.lang.String... locations)
          Loads a new context based on the supplied locations, configures the context, and finally returns the context in fully refreshed state.
 java.lang.String[] processLocations(java.lang.Class<?> clazz, java.lang.String... locations)
          Simply returns the supplied locations unchanged.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


protected final org.apache.commons.logging.Log logger
Constructor Detail


public JavaConfigContextLoader()
Method Detail


public java.lang.String[] processLocations(java.lang.Class<?> clazz,
                                           java.lang.String... locations)
Simply returns the supplied locations unchanged.

Specified by:
processLocations in interface org.springframework.test.context.ContextLoader
clazz - the class with which the locations are associated: used to determine how to process the supplied locations.
locations - the unmodified locations to use for loading the application context; can be null or empty.
an array of application context resource locations
See Also:
ContextLoader.processLocations(Class, String[])


public org.springframework.context.ApplicationContext loadContext(java.lang.String... locations)
Loads a new context based on the supplied locations, configures the context, and finally returns the context in fully refreshed state.

Configuration locations are either fully-qualified class names or base package names. These locations will be given to a JavaConfigApplicationContext for configuration via the JavaConfigApplicationContext.addConfigClass(Class) and JavaConfigApplicationContext.addBasePackage(String) methods.

Specified by:
loadContext in interface org.springframework.test.context.ContextLoader
locations - the locations to use to load the application context
a new application context
java.lang.IllegalArgumentException - if any of locations are not valid fully-qualified Class or Package names