![](/img/trans.png)
[英]How do I resolve spring configuration property without @ConfigurationProperties?
[英]How do I tell Spring to skip loading a Configuration class based on a property?
我知道使用@Profile
批注,您可以告訴Spring僅在使用指定的配置文件時才加載特定的類,如下所示:
@Configuration
@Profile("dev")
public class MyCustomConfigurationClass {
// this will only be instantiated when the "dev" profile is active
}
但是我想知道對於給定的應用程序屬性/環境變量是否有某種等效的方法? 這是一些偽代碼來說明我想做什么:
@Configuration
@OnlyInstantiateWhen(property = "${my.property}", value = "true")
public class MyCustomConfigurationClass {
// this would theoretically only be instantiated when
// the value of my.property is true, either in application.properties
// or in an environment variable
}
這樣有可能嗎?
看一下您自己條件的實現,或使用@ConditionalOnProperty()
類的[對此問題]建議的答案。 ( 有條件的春豆創建 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.