[英]re-using spring configuration properties in nested map
我有一个支持多租户的 Spring Boot 应用程序。 我希望支持一堆自定义配置属性的全局和每个租户配置。 对于每个属性,可以配置一个全局值,但对于特定租户,该值可能会被覆盖。
目前我只有全局属性,使用一些用@ConfigurationProperties
注释的类。 例如
@ConfigurationProperties("props1")
class Props1 {
...
}
@ConfigurationProperties("props2")
class Props2 {
...
}
@ConfigurationProperties("props3")
class Props3 {
...
}
我希望能够像这样配置属性:
props1.a=...
props1.b=...
props2.x=...
props2.y=...
props3.z=...
tenant.some-tenant-id.props1.b=...
tenant.some-tenant-id.props3.z=...
tenant.some-other-tenant-id.props2.x=...
我正在考虑添加另一个@ConfigurationProperties
类,例如前缀为tenant
,并为每个现有类添加一个Map
,其中键将是租户名称,例如:
@ConfigurationProperties("tenant")
class TenantSpecificProps {
private Map<String, Props1> props1;
private Map<String, Props2> props2;
private Map<String, Props3> props3;
...
}
但是,我担心重用用@ConfigurationProperties
注释的类可能会导致以后出现问题,因为这不是 Spring 中使用这些类的正常方式。 此外,我需要手动合并全局和每个租户的值(每个租户覆盖全局值)。
这是一种有效的方法,和/或是否有更惯用的方法来做到这一点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.