-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Add @ConfigurationPropertyValue annotation #8385
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
Conversation
...investigating the cause for the build failure... |
Thanks for the PR. Unfortunately, we are currently rewriting the binding mechanism from scratch (almost) which would make the core of this PR outdated. I am not sure when that's going to land in master but surely everything else (including the test) should be a very good base. WDYT @philwebb ? |
I'll ask next time before starting on an issue :-). I'll gladly re-implement this feature on top of the new binding mechanism (if it's not included yet) if you give me a trigger here once it's merged. |
Will using |
@thombergs The plan is to support interface based binding. It's turning out to be be quite a chunk of work so it's not yet ready to merge into master. |
@thombergs I might give this a try next week with current |
@snicoll Sure, just give me a heads-up when you're done. Just to be sure: only the fallback mechanism for now and leave the default value mechanism for later, correct? |
Sorry that wasn't clear. If you don't have time to rework the PR, I'll give it a try as we'd like this feature to go in. So please let me know if you have time to work on that short term.
Yes (we don't have interface binding yet so that's not necessary for now) |
I misunderstood. I thought you meant you were going to do the binding mechanism rework, but that obviously already happened. I will look into it starting tonight and will probably need a couple nights to grasp the new binding concepts and re-integrate the fallback mechanism. I will submit a new PR then. |
@thombergs Thanks. If you get anywhere could you please do a force push to this branch, rather than opening a new PR. |
Will do. |
I force pushed a re-implementation on top of the new binding mechanism. The For a fallback to function over different property namespaces, I had to remove a check that skipped binding when no property was found in a namespace (see commit 804955f). I couldn't see any side effects, but you probably should look into it. Implementing this on top the refactored binding mechanism was a lot more straight forward than on the old version, so the refactoring definitely pays off ;). |
c2b5c42
to
48eecdc
Compare
updated this pull request to work with current master |
Added onNull() to BindHandler to be able to react to properties that bind to null to choose a fallback value instead. ConfigurationPropertyValue annotations (which allow defining a fallback value for a property) are now collected by ConfigurationPropertyValueReader and a map of fallback properties is passed into a FallbackBindHandler. The handler then reacts on a null value by providing the fallback value instead of the null value. Removed checking for descendant properties, because otherwise fallback properties must always be from the same namespace. Fixes spring-projects#7986
Updated this PR again on top of current master and squashed it to a single commit. I added a rather ugly |
CollectionBinderTests.
Thanks for the update. I think we'll need to review this as part of the wider push to support interface based configuration properties. Unfortunately, that's unlikely to happen until Boot 2.1 now :( |
We've been discussing configuration properties again today as a team and we're starting to feel like the supporting fallback options might not be the best idea in the long run. It feels like a feature that could persuade users to create overly complex property structures. We've decided that for now, we're better off suggesting that people implement fallback scenarios directly in their code. Thanks very much for your efforts with this, and I'm sorry that we didn't manage to solidify our thoughts sooner. |
Adds the
@ConfigurationPropertyValue
annotation as proposed in issue #7986. Fixes issue #7986 if merged.The annotation supports defining a fallback property to bind if the original property is not available and defining a default value which is bound if the fallback property also fails (or is not defined).
Changes are covered with unit tests and I added a short example of the annotation to the feature docs.
Looking forward to feedback :).