spring-projects / spring-projects/spring-boot

Missing callback-Method "onBind" in org.springframework.boot.context.properties.bind.BindHandler

Open
#36,479 4 comments 0 reactions 1 assignee View on GitHub

@philwebb is already working on this.

Since Aug 31, 2023.

status: pending-design-work type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

Hello!

There are several methods for influencing / processing PropertyBinding using org.springframework.boot.context.properties.bind.BindHandler.
But I miss a callback-method like "onBind" that is called when binding takes places.
This method should be called in org.springframework.boot.context.properties.bind.Binder#bindProperty before calling the converter but after resolving placeholders (btw.: I use version 2.6.11).

I try to explain my case as short as possible:
I have to retrieve credentials / URLs etc. from a vault. Unfortunately I cannot use any of the standard-ways to retrieve via configuration / inject the credentials. The only way to do it, is to use a company-specific-proprietary library.
All I want to do is to describe the credentials in my configuration in my own format and to resolve it during binding using the proprietary library, small example:

mysystem:
  secret: secret-spec{'safe':'${safe}','aimUser':'${aimUser}','objectName':'content'}

I build my own BindHandler, that just has a look at the given String and evaluates its specification. Then it uses the proprietary library to retrieve the specified value and returns it.

My solution works fine for Strings (BindHandler#onSuccess, even if it is late!), but fails for URLs etc. because the
Converter cannot resolve something like secret-spec{....}. So I currently use onFailure for this situation.
Not nice, would be perfectly working with a "onBind"-Method.

Please add the mentioned callback to make BindHandler more powerful.

Kind regards
Hans

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.