1

We have this line in our Spring applicationContext.xml:

<context:property-placeholder location="classpath*:*.properties" />

But it's not finding and substituting particular property value which we think it ought to be. Is there any way for us to make this particular property-placeholder tell us the paths it's looking through, the files it's looking in and the properties it's seeing?

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
Robert Atkins
  • 23,528
  • 15
  • 68
  • 97

3 Answers3

4

You can subclass PropertyPlaceHolderConfigurer, something like this:

public class LoggingPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

    @Override
    public void setLocations(final Resource[] locations) {
        if(logger.isDebugEnabled())
            for (final Resource resource : locations) {
                logger.debug("Using resource: " + resource);
            }
            super.setLocations(locations);
    }

    @Override
    protected Properties mergeProperties() throws IOException {
        final Properties mergedProperties = super.mergeProperties();
        if(logger.isDebugEnabled())
            for (final Entry<String, Object> propertyEntry :
                new TreeMap<String, Object>((Map) mergedProperties).entrySet()) {

                logger.debug(
                    "Key:" + propertyEntry.getKey()
                + ", value:" + propertyEntry.getValue());
            }
        return mergedProperties;
    }

}

Now wire your custom class manually (namespace won't work):

<bean class="path.to.LoggingPlaceholderConfigurer">
  <property name="locations" value="classpath*:*.properties" />
</bean>

And set your logging configuration so that log level debug is active for LoggingPlaceholderConfigurer

(This is meant to be a temporary replacement for <context:property-placeholder> for debugging purposes only)

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
0

I don't think so, but you can get the current classpath by calling System.getProperty("java.class.path")

Raghuram
  • 51,854
  • 11
  • 110
  • 122
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
0

you could attach spring framework sources into your project and using debugging, you could see which property files are found/read. I think it is a project configuration/packaging/deployment problem. try to make a copy of your property file, say my.properties and put into one of the packages and see if it is working. If it works, then you need to re-configure your classpaths.

Erhan Bagdemir
  • 5,231
  • 6
  • 34
  • 40