For my unit tests I'm trying to override the "property-sources[0]" element of my spring cloud azure configuration so that it is not used during unit tests.
But it seems that the changes done in my application-test.yaml file is not used for the list element and I don't know what the issue, or the correct way to do it, is.
The changes done to the spring.datasource is correctly applied (in memory database is started and the log states: The following 1 profile is active: "test") but the build fails. Because when starting the test, my application tries to connect with the Azure Key Vault defined in the application.yaml:
java.lang.IllegalStateException: Failed to configure KeyVault property source
...
Caused by: java.net.UnknownHostException: my.vault.azure.net
Testclass (Kotlin):
@SpringBootTest
@ExtendWith(MockitoExtension::class)
@ActiveProfiles("test")
internal class BrablTest {...}
application.yaml:
spring:
datasource:
url: jdbc:sqlserver://localhost:1433;databaseName=my_db;applicationName=myApp;disableStatementPooling=false;enablePrepareOnFirstPreparedStatementCall=true;statementPoolingCacheSize=20
username: my_user
password:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerXADataSource
cloud:
azure:
keyvault:
secret:
property-sources[0]:
credential:
managed-identity-enabled: true
endpoint: https://my.vault.azure.net/
application-test.yaml:
spring:
datasource:
url: jdbc:h2:mem:testdb
cloud:
azure:
keyvault:
secret:
property-sources[0]:
enabled: false
endpoint: https://local.vault.azure.net/
Versions:
Help would be appreciated.
Thanks @spencergibb for pointing it out. I've read the documentation again and it is written there, that because of the higher priority only the values from "application.yaml" are taken.
When a List is specified in multiple profiles, the one with the highest priority (and only that one) is used.
Externalized Configuration (order)
Config data files are considered in the following order:
- Application properties packaged inside your jar (application.properties and YAML variants).
- Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).