我有一個這樣的 application.property:
somevalue.api.test=something
somevalue.anotherproperty=stuff
我做了一個這樣的配置bean:
@Configuration
@ConfigurationProperties("somevalue")
public class SomeProperties {
@NotNull
private String apiTest;
@NotNull
private String anotherproperty;
}
可以參考api.testlikeapiTest嗎?
主要是我的問題是我想使用這somevalue兩個屬性的起點。我知道如果我不使用點分隔 apiTest 并且我以這種方式使用它,somevalue.api-test我可以apiTest在我的 bean 中參考它,但在我的情況下,它不可能重命名。那么通過點分隔我可以達到相同的結果還是我應該創建兩個單獨的配置bean,一個參考somevalue.api而另一個只參考somevalue?
uj5u.com熱心網友回復:
如果您不能重命名該屬性,那么不,您不能使用String apiTest. 您需要一個額外的類,如下所示:
@Configuration
@ConfigurationProperties("somevalue")
public class GcssProperties {
@NotNull
private GcssApiProperties api;
@NotNull
private String anotherproperty;
}
public class GcssApiProperties {
@NotNull
private String test;
}
這應該有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/419248.html
標籤:
