From 84c28995fb2ffa96d2b76d1ad968ba76a00bf1a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Wed, 25 Oct 2023 11:20:21 +0200 Subject: [PATCH] Improve documentation for the default profile Closes gh-29071 --- .../modules/ROOT/pages/core/beans/environment.adoc | 5 +++-- .../springframework/context/annotation/Profile.java | 10 +++++++++- .../springframework/core/env/AbstractEnvironment.java | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/core/beans/environment.adoc b/framework-docs/modules/ROOT/pages/core/beans/environment.adoc index 8dcc44c9cc..eaf43769ce 100644 --- a/framework-docs/modules/ROOT/pages/core/beans/environment.adoc +++ b/framework-docs/modules/ROOT/pages/core/beans/environment.adoc @@ -562,8 +562,9 @@ 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 -the `Environment` or, declaratively, by using the `spring.profiles.default` property. +The name of the default profile is `default`. You can change the name of +the default profile by using `setDefaultProfiles()` on the `Environment` or, +declaratively, by using the `spring.profiles.default` property. diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Profile.java b/spring-context/src/main/java/org/springframework/context/annotation/Profile.java index 2dae20439a..b128bf9208 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Profile.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Profile.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,14 @@ import org.springframework.core.env.Profiles; * for web applications. Profiles may also be activated declaratively in * integration tests via the {@code @ActiveProfiles} annotation. * + *

If no profile is active using one of those options, a default profile is + * enabled as a fallback. The name of the default profile is + * {@value AbstractEnvironment#RESERVED_DEFAULT_PROFILE_NAME}. This can be changed + * via {@link ConfigurableEnvironment#setDefaultProfiles} or declaratively by + * setting the {@link AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME + * spring.profiles.default} property as a JVM system property, as an environment + * variable, or as a Servlet context parameter in {@code web.xml} for web applications. + * *

The {@code @Profile} annotation may be used in any of the following ways: *