We are currently having one application.properties and one application-staging.properties, which is loaded based on the active Spring profile.
However, it's very bloated and we like to split it into multiple properties files based on the context.
For example:
teams.properties and
teams-staging.properties
We load it using the class below
@Getter
@Configuration
@PropertySource("classpath:teams.properties")
public class TeamsProperties {
@Value("${teams.some-team-a}")
private String someTeamA;
@Value("${teams.some-team-b}")
private String someTeamB;
}
But it won't respect the profile and the teams-staging.properties is ignored.
What would be needed to "clone" the default application.properties behaviour for custom properties files?
@PropertySource accept an array as value. You can do this :
Then run the application with the active profile :
The disadvantage of this solution is that you always have to pass only one active profile. It will not work for multiple profiles :
-Dspring.profiles.active=foo,barEdit:
@MarianKlühspies Following your answer, you can have more flexibily using YAML instead of properties file to achieve this behavior.