From 6eae09ba68c3828146d0a7b71bab4d530cb26cbf Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Tue, 25 Mar 2025 11:18:47 +0800 Subject: [PATCH] Document the semantic of using multiple profile expressions This commit clarifies the semantic of declaring multiple profile expression with the "spring.config.activate.on-profile" property. See gh-44866 Signed-off-by: Yanming Zhou --- .../reference/pages/features/external-config.adoc | 4 +++- .../context/config/ConfigDataPropertiesTests.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc index 6b68bd6a4dd..e7b6f42d17a 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/external-config.adoc @@ -545,7 +545,9 @@ The following activation properties are available: | Property | Note | `on-profile` -| A profile expression that must match for the document to be active. +| A profile expression that must match for the document to be active, +or a list of profile expressions of which at least one must match for the document to be active. +Please note comma-separated list such as `foo,bar` is equal to `foo\|bar` instead of `foo&bar`. | `on-cloud-platform` | The javadoc:org.springframework.boot.cloud.CloudPlatform[] that must be detected for the document to be active. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java index b3635903f2e..d37b970d4d0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -200,6 +200,17 @@ class ConfigDataPropertiesTests { assertThat(properties.isActive(context)).isFalse(); } + @Test + void isActiveAgainstBoundDataWhenProfilesMatchCommaSeparatedList() { + MapConfigurationPropertySource source = new MapConfigurationPropertySource(); + source.put("spring.config.activate.on-profile", "a&b,nonexistent"); + Binder binder = new Binder(source); + ConfigDataProperties properties = ConfigDataProperties.get(binder); + ConfigDataActivationContext context = new ConfigDataActivationContext(NULL_CLOUD_PLATFORM, + createTestProfiles()); + assertThat(properties.isActive(context)).isTrue(); + } + @Test void getImportOriginWhenCommaListReturnsOrigin() { MapConfigurationPropertySource source = new MapConfigurationPropertySource();