Spring Framework version is 5.2.5.RELEASE.


org.springframework.beans.factory.support.AbstractBeanFactory#resolveEmbeddedValue

Spring When default value is configured for property placeholder in @Value, subsequent embedded value resolvers are asked to resolve the default value instead of the original value


Example configuration

@Value("${server.servlet.context-path:/}")

Current behavior

  1. When there are multiple embeddedValueResolvers registered in the AbstractBeanFactory and the first resolver cannot resolve the supplied value, then return /.
  2. The return value / is supplied as the argument for the next resolver's resolveStringValue() method, and even if the next resolver is configured to handle resolution of server.servlet.context-path, the final result is always /.

Comment From: sbrannen

@DS4XM, have you configured an explicit PropertySourcesPlaceholderConfigurer bean in your ApplicationContext?

Comment From: sbrannen

@DS4XM, I took the liberty of rewording this issue's title and description.

If I misunderstood your intentions and rephrased things incorrectly, please let me know so that we are certain that we understand what you are trying to convey.

Comment From: DS4XM

Yes, in the project have configured an explicit PropertySourcesPlaceholderConfigurer bean to resolve some custom properties file.

Then I configured a value in application.yml, but the application still obtains the default value, and when I configure the value in a custom properties file, it works.

Comment From: sbrannen

Then I configured a value in application.yml,

It sounds like you're using Spring Boot instead of the core Spring Framework on its own.

Can you please provide a complete yet minimal sample application (i.e., one that we can download from a GitHub repository or zip file) that demonstrates the behavior you are experiencing?

Comment From: DS4XM

I'm sorry to get back to you now. Here is the demo git url: https://github.com/DS4XM/demo.git

Comment From: sbrannen

Thanks for providing the demo application.

Before I look into that in detail, please allow me to clarify something first.

Is the behavior you are describing a regression for use cases that were supported in previous versions of the Spring Framework?

If so, which versions?

Or are you rather making a proposal for a change in behavior in the Spring Framework?

Or are you simply asking for assistance in achieving your goal in your own application without a change to the Spring Framework?

Comment From: DS4XM

the Spring Framework version is 5.2.5.RELEASE

Comment From: sbrannen

the Spring Framework version is 5.2.5.RELEASE

OK. That is the version you are currently using.

Did your application work as expected in a version prior to 5.2.5?

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: DS4XM

i am sory to late too response, in the demo application spring version is 5.2.5, the prior version without use

Comment From: snicoll

@DS4XM with extension of PropertyPlaceholderConfigurer and other unrelated change in your sample, I am afraid we can't really justify spending the time to figure out what you've tried to describe. If you can share a sample that is minimal with clear instructions on how to reproduce, we can reopen this issue.