I know it's possible to have some values bound from a properties file in Spring, like so:
class Foo {
@Value("${some.config.property}")
String value;
...
}
On the current project I'm working for they are keen to use the immutables library.
They have an immutable "class" with some validation that needs some configurable properties. An example:
@Value.Immutable
public interface Foo extends Bar {
...
String getValue();
@Value.Check
default void validate() {
Preconditions.checkArgument(getValue().length() <= 2000, //<-- this should be a configurable value
"Value may not contain more than 2000 characters.");
}
}
This will generate some immutable style class like:
@Generated({"Immutables.generator", "Foo"})
public final class ImmutableFoo implements Foo {
private final String value;
private ImmutableFoo(String value) {
this.value = value;
}
private static ImmutableFoo validate(ImmutableFoo instance) {
instance.validate();
return instance;
}
}
The length of value needs to be configurable for different environments, but I can't seem to figure out to have something configurable in an already existing interface. Is it even possible?