接口 ContextLoader
- 所有已知子接口:
SmartContextLoader
- 所有已知实现类:
AbstractContextLoader
,AbstractDelegatingSmartContextLoader
,AbstractGenericContextLoader
,AbstractGenericWebContextLoader
,AnnotationConfigContextLoader
,AnnotationConfigWebContextLoader
,DelegatingSmartContextLoader
,GenericGroovyXmlContextLoader
,GenericGroovyXmlWebContextLoader
,GenericPropertiesContextLoader
,GenericXmlContextLoader
,GenericXmlWebContextLoader
,WebDelegatingSmartContextLoader
public interface ContextLoader
Strategy interface for loading anapplication context
for an integration test managed by the Spring TestContext Framework.Note: as of Spring 3.1, implement
SmartContextLoader
instead of this interface in order to provide support for annotated classes, active bean definition profiles, and application context initializers.Clients of a ContextLoader should call
processLocations()
prior to callingloadContext()
in case the ContextLoader provides custom support for modifying or generating locations. The results ofprocessLocations()
should then be supplied toloadContext()
.Concrete implementations must provide a
public
no-args constructor.Spring provides the following out-of-the-box implementations:
- 从以下版本开始:
- 2.5
- 作者:
- Sam Brannen, Juergen Hoeller
- 另请参阅:
SmartContextLoader
,AnnotationConfigContextLoader
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 ApplicationContext
loadContext(String... locations)
Loads a newcontext
based on the suppliedlocations
, configures the context, and finally returns the context in fully refreshed state.String[]
processLocations(Class<?> clazz, String... locations)
Processes application context resource locations for a specified class.
方法详细资料
processLocations
String[] processLocations(Class<?> clazz, String... locations)
Processes application context resource locations for a specified class.Concrete implementations may choose to modify the supplied locations, generate new locations, or simply return the supplied locations unchanged.
- 参数:
clazz
- the class with which the locations are associated: used to determine how to process the supplied locationslocations
- the unmodified locations to use for loading the application context (can benull
or empty)- 返回:
- an array of application context resource locations
loadContext
ApplicationContext loadContext(String... locations) throws Exception
Loads a newcontext
based on the suppliedlocations
, configures the context, and finally returns the context in fully refreshed state.Configuration locations are generally considered to be classpath resources by default.
Concrete implementations should register annotation configuration processors with bean factories of
application contexts
loaded by this ContextLoader. Beans will therefore automatically be candidates for annotation-based dependency injection using@Autowired
,@Resource
, and@Inject
.Any ApplicationContext loaded by a ContextLoader must register a JVM shutdown hook for itself. Unless the context gets closed early, all context instances will be automatically closed on JVM shutdown. This allows for freeing external resources held by beans within the context, e.g. temporary files.
- 参数:
locations
- the resource locations to use to load the application context- 返回:
- a new application context
- 抛出:
Exception
- if context loading failed