spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Make the property resolver configurable

Open 1zg12 opened this issue 3 years ago • 6 comments

Background

Prior to Spring 5.2, when we need to customize the PropertiesLoader, we can subclass PropertyPlaceholderConfigurer, and override the resolvePlaceholder method.

Now with PropertySourcesPlaceholderConfigurer deprecated PropertyPlaceholderConfigurer, the resolvePlaceholder method has been moved out of the PlaceHolderConfigurer and into a separate PropertyResolver.

Somehow the PropertyResolver is hardcoded [*]: https://github.com/spring-projects/spring-framework/blob/01bea34569cd3dd00e8691a08ab1a2fc53d6c13e/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java#L157

Due to the hardcode, the only way left for developers to override the resolvePlaceholder now becomes to duplicate the whole postProcessBeanFactory method and then provide custom PropertyResolver.

Changes

Instead of hardcoding a PropertyResolver as existing and make it very difficult to customize, this PR will point to a factory method to provide the PropertyResolver as needed.

I believe there is no side effect on this. It only adds the flexibility for customization which has been lost.

Note [*]

Even though PropertyPlaceholderConfigurer was also using a hardcoded class, https://github.com/spring-projects/spring-framework/blob/01bea34569cd3dd00e8691a08ab1a2fc53d6c13e/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java#L210

It's a private inner class, which even doesn't allow override. However, after several redirects, it eventually points to the resolvePlaceholder of the current class implementation https://github.com/spring-projects/spring-framework/blob/01bea34569cd3dd00e8691a08ab1a2fc53d6c13e/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java#L250

1zg12 avatar Apr 05 '21 09:04 1zg12

@1wpro2 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

pivotal-issuemaster avatar Apr 05 '21 09:04 pivotal-issuemaster

@1wpro2 Thank you for signing the Contributor License Agreement!

pivotal-issuemaster avatar Apr 05 '21 09:04 pivotal-issuemaster

@1zg12 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

pivotal-cla avatar Nov 11 '21 09:11 pivotal-cla

@1zg12 Thank you for signing the Contributor License Agreement!

pivotal-cla avatar May 25 '22 02:05 pivotal-cla

hi @rstoyanchev , can you review this ?

1zg12 avatar May 25 '22 14:05 1zg12

Bump up this, as we are still having issue to overwrite this setting in the newer version of spring. Thanks.

1zg12 avatar Sep 01 '22 03:09 1zg12