question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to bind classes with multiple prefixes

See original GitHub issue

I’ve a use case where I need to bind configuration properties based on two prefixes, one of which is determined at runtime. Let’s say the constant prefix is foo and the runtime prefix is bar.

Given a new instance of Java Bean class FooBar, the code should bind all environment variables FOO_, then overwrite with all environment variables BAR_.

public class FooBar {
    private Duration latency = Duration.ofMillis(500L);
    // other properties
    // getters, setters
}

If there are no environment variables FOO_LATENCY or BAR_LATENCY, FooBar.getLatency() is 500 ms. If only one of FOO_LATENCY and BAR_LATENCY is present, FooBar.getLatency() takes its value. If both FOO_LATENCY and BAR_LATENCY are present, FooBar.getLatency() takes the value of BAR_LATENCY.

This SO answer shows a way to do it by repeated binding. It works, but it confusing.

It’d be nice to be able to merge BindResults. Some ideas off the top of my head:

  1. binder.bind accepts multiple prefixes, not just one, latter progressively overwriting the former.
  2. bindResult.mergeWith(anotherBindResult), latter overwriting the former.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
philwebbcommented, May 12, 2021

Spring Cloud would also like this feature.

1reaction
wilkinsonacommented, Apr 16, 2021

One benefit of the multiple prefixes approach is that it would support constructor binding to an immutable type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to bind the same prefix with multiple properties class
Assume that there is a yaml configuration: foo: a: b: c: d: Generally, you will create an object like this:
Read more >
Class and Style Bindings | Vue.js
A common need for data binding is manipulating an element's class list and inline styles. Since class and style are both attributes, we...
Read more >
Class and style binding - Angular
Binding to multiple CSS classeslink. To bind to multiple classes, type the following: [class]="classExpression". The expression can be one of:.
Read more >
JAXB Users Guide - Java EE
Another way to fix this problem is to use the simpler and better binding mode in ... XJC produces one method on the...
Read more >
Guide to @ConfigurationProperties in Spring Boot - Baeldung
Spring Boot has many useful features including externalized ... This way Spring will look for configuration property classes only in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found