Robert Atkins
Robert Atkins

Reputation: 24668

Can I get Spring's <context:property-placeholder /> to tell me what classpaths it's looking in?

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?

Upvotes: 1

Views: 2605

Answers (3)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298898

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)

Upvotes: 4

Bozho
Bozho

Reputation: 597106

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

Upvotes: 0

Erhan Bagdemir
Erhan Bagdemir

Reputation: 5327

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.

Upvotes: 0

Related Questions