You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting with Spring 3.1 applications can specify contextInitializerClasses via context-param and init-param in web.xml.
Goals
For comprehensive testing it should be possible to re-use ApplicationContextInitializer instances in tests as well.
This could be done at the @ContextConfiguration level by allowing an array of ACI types to be specified, and the TCF would allow each to visit the ApplicationContext at the right time.
Deliverables
[x] Introduce a new initializers attribute in @ContextConfiguration.
1. [x] Introduce a new `inheritInitializers` attribute in `@ContextConfiguration`.
- ```
boolean inheritInitializers() default true;
Allow a context to be loaded solely via a custom ApplicationContextInitializer (i.e., without locations or classes)
Initializers must be included in MergedContextConfiguration for determining the context cache key.
Invoke initializers within existing SmartContextLoader implementations.
for example, in AbstractGenericContextLoader.loadContext(...) methods
[x] per the contract defined in the Javadoc for ApplicationContextInitializer: ApplicationContextInitializer processors are encouraged to detect whether Spring's Ordered interface has been implemented or if the @Order annotation is present and to sort instances accordingly if so prior to invocation.
```
Collections.sort(initializerInstances, new AnnotationAwareOrderComparator());
1. [x] Document in Javadoc
1. [x] Document in the reference manual
----
#### Pseudocode Examples
```java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
locations = "/app-config.xml",
initializers = CustomInitializer.class)
public class ApplicationContextInitializerTests {}
// In the following example, an exception would not be thrown even// if no default XML file or @Configuration class is detected.// In other words, the initializer would be responsible for // providing XML configuration files or annotated configuration// classes to the provided context.@ContextConfiguration(initializers = EntireAppInitializer.class)
publicclassInitializerWithoutConfigFilesOrClassesTestextendsBaseTest {}
Rossen Stoyanchev opened SPR-9011 and commented
Status Quo
Starting with Spring 3.1 applications can specify
contextInitializerClassesviacontext-paramandinit-paraminweb.xml.Goals
For comprehensive testing it should be possible to re-use
ApplicationContextInitializerinstances in tests as well.This could be done at the
@ContextConfigurationlevel by allowing an array of ACI types to be specified, and the TCF would allow each to visit theApplicationContextat the right time.Deliverables
[x] Introduce a new
initializersattribute in@ContextConfiguration.Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>[] initializers() default {};
Allow a context to be loaded solely via a custom
ApplicationContextInitializer(i.e., without locations or classes)Initializers must be included in
MergedContextConfigurationfor determining the context cache key.Invoke initializers within existing
SmartContextLoaderimplementations.for example, in
AbstractGenericContextLoader.loadContext(...)methods[x] per the contract defined in the Javadoc for
ApplicationContextInitializer:ApplicationContextInitializerprocessors are encouraged to detect whether Spring'sOrderedinterface has been implemented or if the@Orderannotation is present and to sort instances accordingly if so prior to invocation.Collections.sort(initializerInstances, new AnnotationAwareOrderComparator());
Affects: 3.1 GA
Referenced from: commits 1f93777, 58daeea
11 votes, 15 watchers