Skip to content

fix: resolve config refresh failure with spring.config.import on 2025.0.x#4335

Open
wushiyuanmaimob wants to merge 4 commits into
alibaba:2025.0.xfrom
wushiyuanmaimob:fix/nacos-config-refresh-mismatch-4331
Open

fix: resolve config refresh failure with spring.config.import on 2025.0.x#4335
wushiyuanmaimob wants to merge 4 commits into
alibaba:2025.0.xfrom
wushiyuanmaimob:fix/nacos-config-refresh-mismatch-4331

Conversation

@wushiyuanmaimob

Copy link
Copy Markdown

Describe what this PR does / why we need it

Fix two defects in NacosPropertySourceRefreshListener that prevented dynamic config refresh when using spring.config.import=nacos: on the 2025.0.x branch.

Defect 1: PropertySource name mismatch

  • ConfigData path uses group@dataId naming (NacosConfigDataLoader.java:146)
  • RefreshListener looked for dataId,group (NacosPropertySourceRefreshListener.java:103)
  • Result: target.get(sourceName) always returned null, so refresh never happened

Defect 2: File extension hardcoded

  • RefreshListener hardcoded "properties" as file extension (NacosPropertySourceRefreshListener.java:108)
  • Actual extension (yml/json/xml) was stored in NacosItemConfig.suffix but not propagated
  • Result: yml/json/xml configs were parsed as properties after refresh, causing errors

Does this pull request fix one issue?

Fixes #4331

Describe how you did it

  1. Add suffix field to NacosPropertySource to preserve file extension
  2. Update NacosPropertySourceBuilder and NacosConfigDataLoader to pass suffix when creating NacosPropertySource
  3. Update NacosPropertySourceRefreshListener to:
    • Try both naming conventions (bootstrap dataId,group and ConfigData group@dataId)
    • Read actual file extension from NacosPropertySource.getSuffix() instead of hardcoding "properties"

Describe how to verify it

  1. Set up a Spring Boot 3.x app with spring.config.import=nacos:test-config.yml
  2. Change the config value in Nacos
  3. Verify the app's Environment reflects the new value (previously it would stay at old value)

Regression tests added in NacosPropertySourceRefreshListenerTest.

Special notes for reviews

  • The module has pre-existing checkstyle violations unrelated to this PR
  • Due to project dependency issues in the current branch, tests cannot run locally, but the fix logic is straightforward and covered by unit tests

Verify two defects in NacosPropertySourceRefreshListener:
1. PropertySource name mismatch between ConfigData path (group@dataId) and bootstrap path (dataId,group)
2. File extension hardcoded as 'properties' instead of using actual suffix (yml/json/xml)

Related to alibaba#4331

Signed-off-by: wushiyuan <wushiyuanwork@outlook.com>
….0.x

Fix two defects in NacosPropertySourceRefreshListener that prevented
dynamic config refresh when using spring.config.import=nacos:

1. PropertySource name mismatch: ConfigData path uses 'group@dataId'
   naming while RefreshListener looked for 'dataId,group'. Now tries
   both naming conventions.

2. File extension hardcoded: RefreshListener always used 'properties'
   extension, breaking yml/json/xml configs. Now reads actual suffix
   from NacosPropertySource.

Changes:
- Add suffix field to NacosPropertySource to preserve file extension
- Update NacosPropertySourceBuilder and NacosConfigDataLoader to pass suffix
- Update NacosPropertySourceRefreshListener to handle both naming formats
  and use actual file extension

Fixes alibaba#4331

Signed-off-by: wushiyuan <wushiyuanwork@outlook.com>
@CLAassistant

CLAassistant commented May 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

The tests were adding plain MapPropertySource to propertySources, but the
production code checks for NacosPropertySource type. This caused the refresh
logic to never execute, resulting in test failures where values weren't updated.

Fixed by:
1. Adding NacosPropertySource wrapper to propertySources instead of inner MapPropertySource
2. Specifying "yml" suffix in NacosPropertySource constructor to match test data

Signed-off-by: sywu14 <wushiyuanwork@outlook.com>
@wushiyuanmaimob wushiyuanmaimob force-pushed the fix/nacos-config-refresh-mismatch-4331 branch from 58c013c to 05418be Compare May 27, 2026 02:01
… tests

- YAML parser returns Integer for numeric values, use String.valueOf()
- After replace, new NacosPropertySource uses standard dataId,group naming
@bengbengbalabalabeng

Copy link
Copy Markdown

Will the current PR see any further progress?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants