码迷,mamicode.com
首页 > 编程语言 > 详细

Spring使用注解读取properties文件内的参数

时间:2015-08-11 15:28:28      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

1.

在spring的配置文件中,配置好需要读取的properties文件

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="fileEncoding" value="UTF-8" />
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
                <value>classpath:config.properties</value>
            </list>
        </property>
</bean>

 

2.

config.properties中的参数:

pay.url=http://www.test.com/pay.htm

3.

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class Configuration {
    @Value(value = "${pay.url}")
    private String payUrl;

    public String getPayUrl() {
        return payUrl;
    }

    public void setPayUrl(String payUrl) {
        this.payUrl = payUrl;
    }
}

 

@Value(value = "${pay.url:123}") 代表pay.url默认值为123

Spring使用注解读取properties文件内的参数

标签:

原文地址:http://www.cnblogs.com/fanning/p/4720832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!