简体   繁体   中英

How can I get a list of all properties in PropertyPlaceHolderConfigurer?

I have:

<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:config/common.properties</value>
            <value>classpath:config/env/${env}/environment.properties</value>
        </list>
    </property>
    <property name="ignoreResourceNotFound" value="true" />
    <property name="nullValue" value="@null" />
</bean>

What I'd like to do is a System.out.print all the key/value pairs of properties available when I'm in a *.java file.

I've had the same question. I wanted to get all the property names available in the Environment. I resolved it by iterating through the various PropertySource components. Unfortunately, some of the PropertySource(s) do not expose the property names. For those you have to know the property name and access the values from the property names.

Here are the various PropertySource(s) that I found. (You can get the property names for the enumerable ones, but I haven't found a way for the others.)

// EnumerablePropertySource
MapPropertySource
ServletContextPropertySource
PropertiesPropertySource
SystemEnvironmentPropertySource
PortletConfigPropertySource
PortletContextPropertySource
ServletConfigPropertySource
CommandLinePropertySource
JOptCommandLinePropertySource
SimpleCommandLinePropertySource
CompositePropertySource
PropertiesPropertySource
MockPropertySource
ResourcePropertySource

// Other
PropertySource$StubPropertySource
RandomValuePropertySource
MutablePropertySources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM