-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provide support for ApplicationContextInitializers in the TestContext framework [SPR-9011] #13650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Chris Beams commented
I've asked Scott to weigh in here further to make his case. |
Scott Frederick commented Following Chris' blog post on Unified Property Management in Spring 3.1, I can add custom PropertySource implementations to a stand-alone or web ApplicationContext. I also want to be able to test how the system behaves with and without the custom PropertySource being registered. In order to do this in a test case using |
Chris Beams commented Sam, take a look at this post as well: http://stackoverflow.com/questions/10357985/java-spring-applicationcontext-configuration/10362527 Not the best use case, perhaps, but it does show that folks expect ACI classes and |
Christian Nedregård commented My use case is not specific to testing. I need to be able to set the active profiles on application contexts loaded in non-web containers (e.g. Mule). I would expect my ApplicationContextInitializers to be discovered and executed when defined as beans in xml or set up for classpath scanning. Would it be possible to generalize this issue to encompass both test-support and support for other container-created contexts? |
George P. Stathis commented +1 for the more generalized case. We have the same problem as Scott with |
Sam Brannen commented Christian and George,
It is not feasible to have an
No, this issue is dedicated to providing support for configuring ACIs in the TestContext framework (e.g., via If you would like to see support for configuring ACIs in other deployment environments, please create a separate JIRA issue for that specific use case. Regards, Sam |
Sam Brannen commented If you are watching this issue, please feel free to participate in the discussion regarding the proposed Deliverables and the corresponding Pseudocode Examples listed in this issue's Description. Thanks! Sam |
Sam Brannen commented Completed as described in the message for GitHub commit 58daeea1e2d7f3688057e0131cba5291a6f70fc2:
|
Rossen Stoyanchev opened SPR-9011 and commented
Status Quo
Starting with Spring 3.1 applications can specify
contextInitializerClasses
viacontext-param
andinit-param
inweb.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 theApplicationContext
at the right time.Deliverables
[x] Introduce a new
initializers
attribute 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
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'sOrdered
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());
Affects: 3.1 GA
Referenced from: commits 1f93777, 58daeea
11 votes, 15 watchers
The text was updated successfully, but these errors were encountered: