-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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
dataSourceis 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 theEnvironmentor,
declaratively, by using thespring.profiles.defaultproperty.
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.defaultexist 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