Hello all, used spring boot: 2.2.1.RELEASE Problem: When defining application.yml properties I want to use something like: property: ${FOO:someFallbackWithEnv_${BAR}}

someOtherProperty: ${property}

With @ConfigurationProperties it works as expected but with injection via @Value or in application.yml (someOtherProperty) it fails with "could not resolve BAR". I think it is not expected as FOO was defined as env variable so the other part should not be processed at all IMO.

Comment From: wilkinsona

This is standard behaviour for Spring Framework's PropertyPlaceholderHelper where it recursively resolves the value before considering any default value separated by :. The reason it works with configuration properties is that they use a lenient PropertyPlaceholderHelper that ignores unresolvable placeholders where as @Value processing does not.

I'm not aware of the reasons behind the default value being processed in full before it's then discarded. On the face of it, it feels less efficient than it could be, but there may well be something that I've overlooked. We'll get the Framework team to take a look.

Comment From: FrancoCorleone

Great, I did a quick workaround of setting empty in nested env variable and checked it myself in the code, but it doesn't feel like an intuitive behavior. Thanks

Comment From: snicoll

That looks like a bug to me and I wish we'd resolve the fallback lazily. I'll see what we can do.

Comment From: snicoll

Unfortunately, fixing it goes in the direction of rewriting the parser for supporting the escape of placeholder and separator. This is ongoing but need a new feature release, see #9628