繁体   English   中英

Spring 引导:如何从 application.yml 中读取特定属性并忽略其他属性

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM