-
Notifications
You must be signed in to change notification settings - Fork 38.4k
ContextCustomizer
does not respect lifecycle best practices
#31527
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
You raise some good points.
I agree that the need to cast is unfortunate. For a bit of background, this mechanism/approach has been in place for a while, long before the
Refactoring either of those APIs at this point would likely constitute a breaking change, unless we figure out some way to support the old and the new way of doing things simultaneously -- perhaps something analogous to the @jhoeller, thoughts? |
ContextCustomizer
does not respect lifecycle best practices
Based on the analogy with the web |
I would like to follow-up with a related issue around the same contract. AOT support is really quite hard to get right with A recent example of such problem is #33272 |
org.springframework.test.context.ContextCustomizer
has been introduced to allow implementations to customize the context programmatically. Looking at implementations of the interface, it is primarily used in Spring Boot.The unique method states the following:
There are two main use cases I can see:
Because the context is not refreshed, the second bit should really register a bean definition and let the container creates it like any regular bean.
ConfigurableApplicationContext
does not expose a way to register a bean definition and it does this on purpose to separate the layer of responsability. As a result, we can see a number of implementations using a cast to get access to the registry.The other problem is that by providing
ConfigurableApplicationContext
, the implementation has access to a lot more than it should, in particular on a context that has not been refreshed yet. This leads to issues like spring-projects/spring-kafka#2870.I don't know if the problem is big enough to consider a refactoring but I think the casting does not look right.
The text was updated successfully, but these errors were encountered: