org.springframework.config.java.test
Class JavaConfigContextLoader
java.lang.Object
org.springframework.config.java.test.JavaConfigContextLoader
- All Implemented Interfaces:
- org.springframework.test.context.ContextLoader
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:
@RunWith(SpringJUnit4ClassRunner.class)
@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.
- Author:
- Jim Moore, Chris Beams
- See Also:
ContextConfiguration
Field Summary |
protected org.apache.commons.logging.Log |
logger
|
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 |
logger
protected final org.apache.commons.logging.Log logger
JavaConfigContextLoader
public JavaConfigContextLoader()
processLocations
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
- Parameters:
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.
- Returns:
- an array of application context resource locations
- See Also:
ContextLoader.processLocations(Class, String[])
loadContext
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
- Parameters:
locations
- the locations to use to load the application context
- Returns:
- a new application context
- Throws:
java.lang.IllegalArgumentException
- if any of locations are not valid fully-qualified
Class or Package names