简体   繁体   中英

How to get all the keys defined in property file in spring framework

I need to get all the keys in a property file and store it into a bean variable. For example I need something like below

abc=df
sad=tyh

Then I need to get {abc,sad} . All this thing I need to do using spring framework .Is this can be possible (I know probability of getting this type requirement is very less but just need to know is it possible)

you can try try like define bean in applicationContext like

<bean id="applicationProperties"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath*:*.properties</value>
                <value>classpath*:*.properties</value>
                <value>classpath*:*.properties</value>
                <value>classpath*:*.properties</value>
                <value>classpath*:*.properties</value>
                <value>classpath*:*.properties</value>
                <value>classpath*:*.properties</value>
                <value>classpath*:*.properties</value>
            </list>
        </property>
    </bean>

and declare like

@Resource(name = "applicationProperties")
    private Properties properties;

and getProperty like

String str = properties.getproperty('keyname');
Enumeration allkeys = properties.propertyNames();

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