3
votes

I'm using Sprint Boot, and would like to have multiple profile specific property files. The docs state:

In addition to application.properties files, profile specific properties can also be defined using the naming convention application-{profile}.properties.

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-profile-specific-properties

However I have multiple properties files (e.g. db.properties). I'm loading currently load this non-profile specific file as:

@Configuration
@PropertySource( {"classpath:db.properties"} )
class DataSourceConfig  {
    @Value("db.server") String server;
...
}

How can I combine these two things together, so it loads db-dev.properties like Spring Boot does for application.properties

It sounds like it should be easy, but I can't work out how to do it?!

2
According to the docs it works just the same.a better oliver
I tried db-dev.properties with a @Profiles("dev") annotation and it didn't read the db-dev property in. Do you have a link to the docs where it says that?Mark
There is no such link because it doesn't work that way. Only Spring Boot config files have the "x-<profile>" convention. For @PropertySource you would need to define one per profile with an explicit file path. (In short if you are using Spring Boot, @PropertySource might not be the right tool, but YMMV.)Dave Syer

2 Answers

1
votes

Java -jar my-spring-boot.jar --spring.profiles.active=test you can set profile.active=your environment via commandline

0
votes

I just saw that you use @PropertySource. The docs say:

Profile specific variants of both application.properties (or application.yml) and files referenced via @ConfigurationProperties are considered as files are loaded.