@Profile is not for loading environment specific properties file. It is for specifying profile of a bean. For example,
@Profile("dev")
@Component
class Foo {
}
It means the bean of Foo
is only available when the active profiles include dev
. Or the opposite @Profile("!dev")
, which means the bean is available when dev
is not an active profile.
So for loading environment specific properties file, since it is spring-boot
, you can just specify the active profiles. There are several ways to specify the active profiles.
- Environment variable:
SPRING_PROFILES_ACTIVE=dev,prod
- command line argument:
java -jar app.jar --spring.profiles.active=dev,prod
- Programmatically :
SpringApplicationBuilder(...).properties("spring.profiles.active=dev,prod).run(...)
- Default application.properties or yaml:
spring.profiles.active:dev, prod
application.properties
and anapplication-{profile}.properties
for you. – Welloiled