如何解决Spring Boot 外化配置和 protobuf 构建器
我正在编写使用 protobuf 生成的构建器作为 Spring Boot 外部化配置的 POJO 的概念证明。我的目标是在没有样板的情况下填充第三方 DTO(例如 https://mvnrepository.com/artifact/io.envoyproxy.controlplane/api 中的那些)。
ConfigurationProperties
看起来像:
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;
}
}
}
以下演示显示涵盖了大多数情况,但我无法找到填充嵌套列表的方法:https://github.com/colltoaction/spring-boot-configuration-proposal。
生成的代码(见 https://developers.google.com/protocol-buffers/docs/reference/java-generated#builders)有很好的文档记录,我想 Spring Boot 可以采用这些约定并将它们添加到现有的约定中。支持这种与 protobuf 的无样板集成可能是一个很好的补充。
例如:读取外部属性时,不仅使用 getFoo()
和 setFoo(Foo)
方法,还使用 addFoo(Foo)
或 setFoo(index,Foo)
。
我更愿意通过我正在使用的版本(Spring Boot 2.3.4)找到一种方法来做到这一点,但如果不可能,我愿意为 Spring Boot 源代码做出贡献。
有什么想法吗??
提前谢谢??
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。