Spring Active profile setup for existing application

Solution 1:

First of all, please check what profile the application is using, search for line like this (in log):

The following profiles are active: test

When I tested with Spring Boot v2.2.2.RELEASE, application_test.yml file is not used, it has to be renamed to application-test.yml, for a better highlighting of a difference:

application_test.yml # NOT working
application-test.yml # working as expected

What I like even more (but it is Spring Boot specific), you can use application.yml like this:

foo: 'foo default'
bar: 'bar default'

---
spring:
  profiles:
  - test
bar: 'bar test2'

Why I prefer this? Because you can use multiple profiles then, e.g. profile1,profile2 and it behaves as last wins, I mean it will override the values from profile1 with values from profile2, as it was defined in this order... The same does not work with application-profileName.yml approach.