'Ignore specific property when running a Spring Boot test

My Spring Boot application contains the following property in src/main/resources/application.yml:

spring:
 security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: ${AUTH_SERVER_METADATA_URL:http://localhost:8080/auth/realms/demo}

When running tests, e.g. @WebMvcTest, I don't have a running authorization server. Thus, I need to use the following configuration which I put into src/test/resources/application-test.yml and activate it by using the @ActiveProfiles("test") annotation.

spring:
 security:
    oauth2:
      resourceserver:
        jwt:
          public-key-location: classpath:public_rsa.key

The problem is, that the application context loads both of the application property files which leads to a refused connection during the tests. Is it possible to selectively ignore the issuer-uri property during tests?



Solution 1:[1]

If you rename src/test/resources/application-test.yml to src/test/resources/application.yml, it should override the file src/main/resources/application.yml

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Erwan Leroux