Work Circuit : /src/main/resources
Test Circuit : /src/test/resources
application.yaml
main:
car:
name: "Audi"
id: "10201"
application-local.yaml
main:
car:
name: "Mercedes"
id: "10200"
@SpringBootApplication
public class SpringProfilesApplication {
public static void main(String[] args) {
SpringApplication.run(SpringProfilesApplication.class, args);
}
@Bean
CommandLineRunner commandLineRunner(ProfileMain profileMain) {
return args -> {
profileMain.printMainName();
};
}
}
@Component
public class ProfileMain {
@Value("${main.car.name}")
private String name;
@Value("${main.car.id}")
private String id;
public void printMainName() {
System.out.println("\n name in Main application.yaml : " + this.name + "\n");
System.out.println("\n name in Main application.yaml : " + this.id + "\n");
}
}
– When you run the main class, without specifying any profiles, application.yaml will be used.
– You can specify the profile you need in the development environment

Now the settings of those properties that were in the main application.yaml, will be overridden in the specified profile - local.
If the selected profile does not contain the settings that are in the main application.yaml, then the missing properties will be taken from the main application.yaml.
@SpringBootTest(classes = SpringProfilesApplication.class)
class ProfileMainTest {
@Value("${main.car.name}")
private String name;
@Value("${main.car.id}")
private String id;
@Test
void printMainName() {
System.out.println("\n In test circuit : " + name);
System.out.println("\n In test circuit : " + id);
}
When we do not explicitly specify a profile, the settings will be taken from the main application.yaml.
Now we use the *.yaml file from the test loop.
application-test.yaml
main:
car:
name: "Nissan"
id: "10203"
@SpringBootTest(classes = SpringProfilesApplication.class)
@ActiveProfiles("test")
class ProfileMainTest {
...
}
Here the properties (if any) will be redefined, that is, taken from the application-test.yaml file.
But if there is no property, then it will be taken from the main file
application.yml.
In the Working circuit
- If the profile is not specified, the settings will be taken from the main application.yaml.
- If a profile is specified, then the settings from this profile will override the settings from the main application.yaml file.
If some settings are missing, then the settings will be taken from the main application.yaml file(if any).
In the test circuit
- If the profile is not specified, the settings will be taken from the main application.yaml.
- If a profile is specified, then the settings from this profile will override the settings from the main application.yaml file.
If some settings are missing, then the settings will be taken from the main application.yaml file (if any).