简体   繁体   中英

Spring boot: how to read specific property from application.yml and ignore others

My goal is to read some property from application.yml file and ignore other properties. This is need for testing purposes - I want to read part of config and validate it. I want to ignore other properties because Spring Boot tring to handle it but this is no need for my test. Example.

Config:

first:
 property:
  {cipher}value    #for example Spring trying to handle cipher and throws exception

second:
 property:
  value

Class ( using String for simplification ):


@Configuration
public class Configuration {

  @Bean
  @ConfigurationProperties(prefix = "second.property")
  public String secondProperty() {
      return new String();
  }
}

Test class:

@SpringBootTest
public class ConfigPropertiesCheckerIntegrationTest {

    @Autowired
    String secondProperty;

    @Test
    void checkAutoConfigEndpointProperties() {
        assertThat(secondProperty, is(notNullValue()));
    }
}

So question: how to ignore first.property and say Spring just skip it?

You can disable {cipher} ed properties decryption with spring.cloud.decrypt-environment-post-processor.enabled=false . Eg:

@SpringBootTest(properties = "spring.cloud.decrypt-environment-post-processor.enabled=false")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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