Suppose we have following configuration interface:

public interface Configuration {
  String getName();
  void setName(String name);
  int getAge();
  void setAge(int age);
}

This configuration interface will be used in another bean intialization, for example:

public class Factory {
  public Factory(Configuration configuration) {
    // do something
  }
}

To make this bindable, we can just supply a configuration class as following:

@Getter @Setter // lombok annotation to generate getters and setters
@ConfigurationProperties(prefix = "myfactory")
public class MyConfigurationProperties {
  private Configuration configuration;
}

If we can just put following properties together with application.yml as following:

myfactory:
  configuration:
    name: Foo
    age: 24

After doing this, we can just make this factory available, it's awsome!

One possible way to do this would using dynamic proxy such as Cglib or ASM. These kinds of configuration interfaces should only need match fields, but it will make configuration very simple and clean.

Comment From: wilkinsona

Thanks for the suggestion. https://github.com/spring-projects/spring-boot/issues/1254 is tracking binding properties to interfaces. It has been declined (for now at least) but may be re-opened in the future.