[英]Spring boot: how to read specific property from application.yml and ignore others
我的目標是從 application.yml 文件中讀取一些屬性並忽略其他屬性。 這是出於測試目的——我想閱讀部分配置並驗證它。 我想忽略其他屬性,因為 Spring Boot tring 可以處理它,但這對我的測試來說不需要。 例子。
配置:
first:
property:
{cipher}value #for example Spring trying to handle cipher and throws exception
second:
property:
value
Class(使用 String 進行簡化):
@Configuration
public class Configuration {
@Bean
@ConfigurationProperties(prefix = "second.property")
public String secondProperty() {
return new String();
}
}
測試class:
@SpringBootTest
public class ConfigPropertiesCheckerIntegrationTest {
@Autowired
String secondProperty;
@Test
void checkAutoConfigEndpointProperties() {
assertThat(secondProperty, is(notNullValue()));
}
}
所以問題:如何忽略first.property
並說 Spring 只是跳過它?
您可以使用spring.cloud.decrypt-environment-post-processor.enabled=false
禁用{cipher}
ed 屬性解密。 例如:
@SpringBootTest(properties = "spring.cloud.decrypt-environment-post-processor.enabled=false")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.