I'm writing a proof of concept of using protobuf-generated builders as POJOs for Spring Boot externalized configuration. My goal is to populate third-party DTOs (such as the ones in https://mvnrepository.com/artifact/io.envoyproxy.controlplane/api) with no boilerplate.
The ConfigurationProperties
looks like:
public class Properties {
// ExternalProperties and its builder is generated by the protobuf compiler
private final ExternalProperties externalProperties;
private Properties(ExternalProperties externalProperties) {
this.externalProperties = externalProperties;
}
public ExternalProperties getExternalProperties() {
return externalProperties;
}
@ConfigurationProperties
public static class Builder {
private final ExternalProperties.Builder externalPropertiesBuilder =
ExternalProperties.newBuilder();
public Properties build() {
return new Properties(externalPropertiesBuilder.build());
}
public ExternalProperties.Builder getExternalPropertiesBuilder() {
return externalPropertiesBuilder;
}
}
}
The following demo shows that most cases are covered, but I'm unable to find a way to populate nested lists: https://github.com/colltoaction/spring-boot-configuration-proposal.
The generated code (see https://developers.google.com/protocol-buffers/docs/reference/java-generated#builders) is well documented, and I imagine that Spring Boot could take this conventions and add them to the existing ones. Supporting this kind of boilerplate-free integration with protobuf might be a great addition.
E.g: when reading externalized properties not only use getFoo()
and setFoo(Foo)
methods, but also addFoo(Foo)
or setFoo(index, Foo)
.
I would prefer to find a way to do this with the release I'm using (Spring Boot 2.3.4) but I'm open to contributing to the Spring Boot source if it isn't possible.
Any ideas??
Thanks in advance ????
question from:
https://stackoverflow.com/questions/66064382/spring-boot-externalized-configuration-and-protobuf-builders 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…