简体   繁体   English

使用Spring(Java)加载.properties文件

[英]Loading a .properties file with Spring (Java)

I am having an issue with loading a .properties file. 我在加载.properties文件时遇到问题。

The file is called "businessmessages_en_US.properties" and it is stored in "src/main/resources/config/i18n". 该文件称为“ businessmessages_en_US.properties”,并且存储在“ 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: 我在构建路径中添加了“ src / main / resources”,并在我的spring xml中创建了一个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 请注意,“ basename”属性必须是根据类别的字符串

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! 谢谢!

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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