spring-cloud / spring-cloud-commons

Common classes used in different Spring Cloud implementations
Apache License 2.0
709 stars 705 forks source link

Question: Can ConfigurationPropertiesRebinder Refresh Be Aligned with @RefreshScope Behavior? #1374

Open qnnn opened 3 months ago

qnnn commented 3 months ago

Is your feature request related to a problem? Please describe. The ConfigurationPropertiesRebinder refresh mechanism works by performing destroy and initial processes on existing bean objects. During refresh, some property values may not be properly handled (for example, if certain configuration items are deleted, the corresponding property values are not cleared). To clear these property values, I need to add the @RefreshScope annotation and leverage its mechanism to refresh the inner bean. However, I am cautious about using the @RefreshScope annotation because its lazy loading and re-creation behavior may lead to bean retrieval failures or slowdowns (such as exceptions thrown in constructors or lifecycle methods).

Describe the solution you'd like Is it possible to initialize a new bean during the ConfigurationPropertiesRebinder binding process and assign its values to the original bean? This would align the refresh behaviors of @RefreshScope and ConfigurationProperties.

qnnn commented 3 months ago

This seems somewhat similar to the issue mentioned in #1372. Is there already a plan to address this? (Feel free to close this issue and continue the discussion in #1372.)