Skip to content

Ordering of 'spring.config.import' is inconsistent when defined in environment or system properties#49324

Closed
qnnn wants to merge 1 commit intospring-projects:mainfrom
qnnn:main
Closed

Ordering of 'spring.config.import' is inconsistent when defined in environment or system properties#49324
qnnn wants to merge 1 commit intospring-projects:mainfrom
qnnn:main

Conversation

@qnnn
Copy link
Contributor

@qnnn qnnn commented Feb 25, 2026

Description

When spring.config.import is defined in application.properties or application.yml, imported config data contributors are ordered consistently with profile-specific variants according to the PROFILE_SPECIFIC option introduced in #25766 5774ea3#diff-f66c18c64b5580ffa30cf0f1dad18db0dba9a1859b3f48902c6d7835cff0cc6e

However, when spring.config.import is defined via:

  • Java system properties
  • Environment variables

the resulting contributor ordering differs.

Reproducible Scenario

Directory structure:

/mock
 ├── test1.properties
 ├── test1-myprofile.properties
 ├── test2.properties

When configured in application.properties:

spring.config.import=classpath:mock/test1.properties,classpath:mock/test2.properties
spring.profiles.active=myprofile

The resulting precedence order is:

test1.properties
test2.properties
test1-myprofile.properties

However, when configured via environment variables:

SPRING_CONFIG_IMPORT=classpath:mock/test1.properties,classpath:mock/test2.properties
SPRING_PROFILES_ACTIVE=myprofile

The resulting precedence order becomes:

test1.properties
test1-myprofile.properties
test2.properties

This behavior is inconsistent the expected import ordering semantics described in #25766 (Support profile specific ConfigData imports)

Proposed Fix

This PR wraps contributors originating from environment and system property-based spring.config.import definitions in a dedicated contributor wrapper.

This ensures consistent treatment with file-based imports.

…nvironment or system properties.

Signed-off-by: qnnn <qiunan@cmbchina.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 25, 2026
@philwebb philwebb changed the title Fix inconsistent ordering of spring.config.import when defined in environment or system properties Fix inconsistent ordering of 'spring.config.import' when defined in environment or system properties Feb 26, 2026
@philwebb philwebb self-assigned this Mar 6, 2026
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 6, 2026
@philwebb philwebb added this to the 3.5.x milestone Mar 6, 2026
@philwebb philwebb changed the title Fix inconsistent ordering of 'spring.config.import' when defined in environment or system properties Ordering of 'spring.config.import' is inconsistent when defined in environment or system properties Mar 6, 2026
philwebb pushed a commit that referenced this pull request Mar 7, 2026
Update `ConfigDataEnvironment` so `spring.config.import`
properties defined in environment or system properties
are ordered correctly.

See gh-49324

Signed-off-by: qnnn <qiunan@cmbchina.com>
philwebb added a commit that referenced this pull request Mar 7, 2026
@philwebb philwebb closed this in a80fce7 Mar 7, 2026
@philwebb philwebb modified the milestones: 3.5.x, 3.5.12 Mar 7, 2026
@philwebb
Copy link
Member

philwebb commented Mar 7, 2026

Thanks very much @qnnn! I've made a few changes to the fix to lean of the existing contributor kinds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants