Description
In the current reference documentation exists the Default Profile section. It has the following content
Starting with a code:
@Configuration
@Profile("default")
public class DefaultDataConfig {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.HSQL)
.addScript("classpath:com/bank/config/sql/schema.sql")
.build();
}
}
and the following content/explanation:
If no profile is active, the
dataSource
is created. You can see this as a way to provide a default definition for one or more beans.
If any profile is enabled, the default profile does not apply.You can change the name of the default profile by using
setDefaultProfiles()
on theEnvironment
or,
declaratively, by using thespring.profiles.default
property.
Therefore: Why from the beginning was not used directly spring.profiles.active
? - it especially taking in consideration that is known that spring.profiles.active
has more precedence and overrides by complete spring.profiles.default
as indicated in bold above.
As summary:
- Why does
spring.profiles.default
exist if the same approach can be accomplished throughspring.profiles.active
?
Is not clear when is mandatory use the former over the latter - and taking the special consideration about the behavior of overriding if the latter is declared.
Just in case, the @Profile javadoc does not contain some indication about this
I create a post on SO at:
But I think the explanation from the source (here) should be expanded. Thanks for your understanding