-
Notifications
You must be signed in to change notification settings - Fork 38.1k
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
Introduce DynamicPropertyRegistrar
as a replacement for DynamicPropertyRegistry
bean support
#33501
Comments
See spring-projects/spring-boot#41276 for an example of the sort of lifecycle problem that's created by |
DynamicPropertyRegistry
bean registration and support
Thanks for raising your concerns, @philwebb.
Yes, I agree with that.
The decision to use
I don't see how that would be the case. The code has to invoke Or are you referring to a different scenario/perspective?
Indeed. That's currently possible but not exactly straightforward.
I can see the advantages of implementing the feature that way, as it addresses some of the concerns you have raised. The only downside I can foresee is that any bean injected into such a
Assuming you meant the But then Framework would be responsible for processing all
True. We would no longer need to support Since Spring Framework 6.2 RC1 is scheduled for release in two days, we don't have much time left, but we will discuss our options within the team. From my point of view, if we want to enable a migration path for Boot's use of
Though, to be honest, I'm not sure how plausible option 1 is. Thoughts? |
Just to clarify: Wouldn't annotating the |
As I understand it, it would help for Boot 3.4 (where we depend Framework 6.2), but not for earlier versions of Boot as Even with Boot 3.4 and the possibility of using |
I pushed a proof of concept for main...sbrannen:spring-framework:issues/gh-33501-DynamicPropertyRegistrar As stated in the commit message:
@philwebb and @jhoeller, I'd appreciate it you could take a quick look to confirm this is the direction we want to go. If so, I'll work out the aforementioned bug and update the Javadoc and reference manual accordingly. |
Certainly scanning the implementation will make it obvious, but for me it's a bit of an unusual pattern for a
Yes, that might be a problem. I do wonder how useful not doing early initialization will be for most users. I think typically, you want to configure something in the
I agree that option 1 seems quite difficult given the timescales. Even option 3 feels tight. I guess if we can live with delaying the feature until Spring Framework 7, that would be my preference. We still have time in Spring Boot to deprecate our use of |
DynamicPropertyRegistry
bean registration and supportDynamicPropertyRegistrar
as a replacement for DynamicPropertyRegistry
bean support
This is a PROOF OF CONCEPT which introduces DynamicPropertyRegistrar support as a replacement for registering a DynamicPropertyRegistry as a bean in the ApplicationContext. It appears that most things work as expected; however, in this POC there are two instances of DefaultDynamicPropertyRegistry that prevent the use of @DynamicPropertySource and DynamicPropertyRegistrar in the same ApplicationContext, since the two features end up writing to two different valueSuppliers maps. The commented-out "magic.word" assertions in DynamicPropertySourceIntegrationTests therefore currently fail. See spring-projectsgh-33501
With this commit, a DynamicValuesPropertySource is now created and registered with the Environment on demand whenever a DefaultDynamicPropertyRegistry is created, which only occurs once in DynamicPropertiesContextCustomizer and once in DynamicPropertyRegistrarBeanInitializer. In addition, DefaultDynamicPropertyRegistry now operates on the valueSuppliers map stored in the singleton DynamicValuesPropertySource registered with the Environment, which allows @DynamicPropertySource methods and DynamicPropertyRegistrar beans to transparently populate the same DynamicValuesPropertySource. See spring-projectsgh-33501
@philwebb and @wilkinsona, in the end we decided to go with the For details, see e7b52cf. And, Phil, thanks again for the |
Thanks for this @sbrannen. I'm still exploring all of the different permutations, but I think there's a possibility that Boot may be able to use While we're exploring things and evaluating our options, it would be useful to know if you'd be open to allowing Boot to bootstrap Framework's |
#32271 introduced the automatic registration of
DynamicPropertyRegistry
as a bean that can be used in tests, along with support for@DynamicPropertySource
on bean methods. This unfortunately caused spring-projects/spring-boot#41839 due to the fact that Spring Boot already registers aDynamicPropertyRegistry
.In hindsight, I think Spring Boot should not have directly used
DynamicPropertyRegistry
for Testcontainers support, but instead should have created a new interface that deals with the subtle lifecycle issues we're trying to overcome by triggering container events. I would like to change this in Spring Boot 3.4, but it's hard to do in a back compatible way becauseDynamicPropertyRegistry
is not a Spring Boot interface.Ideally, in Spring Boot 3.4 we would create a new interface and also create a
DynamicPropertyRegistry
bean that logs a warning telling folks to migrate. With Spring Framework also addingDynamicPropertyRegistry
bean support, this is not possible.Given that there can be very subtle lifecycle issues with using
DynamicPropertyRegistry
in a bean (you need to ensure that the bean is created before something else accesses the property). I wonder if we can reconsider the way that Spring Framework will handle this. With the current design, it's quite easy to miss that you should annotate your@Bean
method with@DynamicPropertySource
to ensure that it gets created early enough. It's also quite easy to miss that the registry is updated as a side-effect of creating the bean. One final problem is that it's a little hard to see how you can update aDynamicPropertyRegistry
for an existing bean (rather than one you're creating).I wonder if we might have time consider a dedicated
DynamicPropertyRegistrar
interface instead? The interface would accept theDynamicPropertyRegistry
to be updated.In code, I anticipate something like this:
I'm not 100% sure if this will work, but if it does it would free up the
DynamicPropertyRegistrar
bean for Spring Boot to create and use to log migration tips. It would also make it impossible to useDynamicPropertyRegistrar
and forget to add@DynamicPropertySource
. Finally, it would give a good place to document how aDynamicPropertyRegistrar
is created early and to be aware of lifecycle issues. Typically, Testcontainer properties aren't a big problem because theContainer
beans are distinct from the application. For regular app, the lifecycle issues could be very hard to track down.The text was updated successfully, but these errors were encountered: