Skip to content

Commit 84c2899

Browse files
committed
Improve documentation for the default profile
Closes gh-29071
1 parent 925fa02 commit 84c2899

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

framework-docs/modules/ROOT/pages/core/beans/environment.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,9 @@ If no profile is active, the `dataSource` is created. You can see this
562562
as a way to provide a default definition for one or more beans. If any
563563
profile is enabled, the default profile does not apply.
564564

565-
You can change the name of the default profile by using `setDefaultProfiles()` on
566-
the `Environment` or, declaratively, by using the `spring.profiles.default` property.
565+
The name of the default profile is `default`. You can change the name of
566+
the default profile by using `setDefaultProfiles()` on the `Environment` or,
567+
declaratively, by using the `spring.profiles.default` property.
567568

568569

569570

spring-context/src/main/java/org/springframework/context/annotation/Profile.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,6 +38,14 @@
3838
* for web applications. Profiles may also be activated declaratively in
3939
* integration tests via the {@code @ActiveProfiles} annotation.
4040
*
41+
* <p>If no profile is active using one of those options, a default profile is
42+
* enabled as a fallback. The name of the default profile is
43+
* {@value AbstractEnvironment#RESERVED_DEFAULT_PROFILE_NAME}. This can be changed
44+
* via {@link ConfigurableEnvironment#setDefaultProfiles} or declaratively by
45+
* setting the {@link AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
46+
* spring.profiles.default} property as a JVM system property, as an environment
47+
* variable, or as a Servlet context parameter in {@code web.xml} for web applications.
48+
*
4149
* <p>The {@code @Profile} annotation may be used in any of the following ways:
4250
* <ul>
4351
* <li>as a type-level annotation on any class directly or indirectly annotated with

spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,15 +89,15 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
8989

9090
/**
9191
* Name of reserved default profile name: {@value}. If no default profile names are
92-
* explicitly and no active profile names are explicitly set, this profile will
92+
* explicitly set and no active profile names are explicitly set, this profile will
9393
* automatically be activated by default.
9494
* @see #getReservedDefaultProfiles
9595
* @see ConfigurableEnvironment#setDefaultProfiles
9696
* @see ConfigurableEnvironment#setActiveProfiles
9797
* @see AbstractEnvironment#DEFAULT_PROFILES_PROPERTY_NAME
9898
* @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
9999
*/
100-
protected static final String RESERVED_DEFAULT_PROFILE_NAME = "default";
100+
public static final String RESERVED_DEFAULT_PROFILE_NAME = "default";
101101

102102

103103
protected final Log logger = LogFactory.getLog(getClass());

0 commit comments

Comments
 (0)