Mike
Mike

Reputation: 124

Loading a .properties file with Spring (Java)

I am having an issue with loading a .properties file.

The file is called "businessmessages_en_US.properties" and it is stored in "src/main/resources/config/i18n". I have added "src/main/resources" to the build path and in my spring xml I have created a bean:

<bean name="messageResource" id="messageResource"
    class="[package].CustomResourceBundleMessageSourceImpl">
    <property name="basename">
        <value>classpath*:config/i18n/*.properties</value>
    </property>
</bean>

Note that the "basename" property must be a string according to the class

Yet every time I run my program, the logger shoots a message:

01 Jul 2013 09:12:34,267 WARN [package].CustomResourceBundleMessageSourceImpl - ResourceBundle [classpath*:config/i18n/*.properties] not found for MessageSource: Can't find bundle for base name classpath*:config/i18n/*.properties, locale en_US 

I need the program to read this file so that the logger can have the correct values. Any help would be greatly appreciated. Thank you!

Upvotes: 0

Views: 2715

Answers (1)

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22516

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

and then use it like this:

    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="${database.driverClassName}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
    </bean>

Upvotes: 1

Related Questions