I am working with a Java Spring Boot application (Spring boot version 3.x.x) that used the legacy way of configuring connection to the config server via the bootstrap.yml file.
I am trying to remove the bootstrap file and move everything to the application.yml file. The config file contains config for the default profile as well as for the test profile.
Here is a sample of the application.yml file with the relevant properties:
spring:
profiles:
active: live
config:
import: configserver:https://someconfigserverurl
---
spring:
config:
activate:
on-profile: test
The issue is that whenever I am running an integration test with the test profile active it fails because it tries to first connect with the config server.
What I would like to do is config the app to only use config server for the live profile and use the yaml file for the test profile without attempting to connect to the config server.
I have tried adding spring.config.import:classpath:/application.yml
under the **test **profile, however it did not work.
The workaround I have used to make it work was to disable the fail fast option from the live profile via `spring:config:import: optional:configserver’.
I found this explanation in the official docs for Spring Cloud Config:
Spring Boot Config Data resolves configuration in a two step process. First it loads all configuration using the default profile. This allows Spring Boot to gather all configuration which may activate any additional profiles. After it has gathered all activated profiles it will load any additional configuration for the active profiles.
What I understand from here is that Spring Boot will always read the configs for the default profile and will first try to connect to the config server and only then it will look into the properties of other profiles. This would mean there would be no solution to what I m looking for.
To sum it up, would it be possible to configure the app to try connecting to the config server only on the live profile?