0

I have the following config in a spring applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util.xsd">

    <context:property-placeholder location="file:///absolute/path/to/foo.properties"/>

    <context:property-placeholder location="file:///absolute/path/to/bar.properties"/>
    <util:properties id="baz" location="file:///absolute/path/to/bar.properties"/>

I can put debug breakpoints where the property files are loaded and see the property files' values are indeed loaded.

But in my bean, @Value("#{baz.myProp}") is resolved whereas @Value("${myProp}") blows up in PropertyPlaceholderHelper, as PropertySourcesPropertyResolver can't find myProp:

DEBUG [...] - Searching for key 'myProp' in [environmentProperties]
DEBUG [...] - Searching for key 'myProp' in [systemProperties]
DEBUG [...] - Searching for key 'myProp' in [systemEnvironment]
DEBUG [...] - Could not find key 'myProp' in any property source. Returning [null]
DEBUG [...] - Searching for key 'myProp' in [localProperties]
DEBUG [...] - Could not find key 'myProp' in any property source. Returning [null]

Why is that and how can I make it work (using the $ property placeholder resolution, instead of the # SpEL syntax)?

Do the properties loaded via context:property-placeholder get discarded/overwritten by util:properties (which is only accessible via the baz reference)?

Christian
  • 6,070
  • 11
  • 53
  • 103

1 Answers1

0

Turns out this is all that needs to go on each of the context:property-placeholder lines to give each one a chance to take part in resolving the property: ignore-unresolvable="true"...

Christian
  • 6,070
  • 11
  • 53
  • 103
  • 1
    Don't (as you will probably miss important exceptions). Use a single `property-placeholder` with a comma separated list of locations. – M. Deinum Oct 09 '17 at 13:16