spring 配置文件使用

配置文件主要是为了方便项目上线后配置信息随时改变,比较灵活。公司使用的paoding rose,和spring大体差不多。
1. 配置文件bean

package com.xx.gamecenter.dashboard.bean;

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

/**
 * @author zexi
 * @time 2016年10月20日 下午1:41:30
 * 用户信息判定文件
 */
@Component
public class FilePathConfig {

    @Value("#{propertyConfigurer['woman.packagename.file.path']}")
    private  String womanPackageNameFilePath;
    @Value("#{propertyConfigurer['man.packagename.file.path']}")
    private  String manPackageNameFilePath;
    @Value("#{propertyConfigurer['student.packagename.file.path']}")
    private  String studentPackageNameFilePath;
    @Value("#{propertyConfigurer['internetuser.packagename.file.path']}")
    private  String internetuserPackageNameFilePath;

    public String getWomanPackageNameFilePath() {
        return womanPackageNameFilePath;
    }
    public void setWomanPackageNameFilePath(String womanPackageNameFilePath) {
        this.womanPackageNameFilePath = womanPackageNameFilePath;
    }
    public String getManPackageNameFilePath() {
        return manPackageNameFilePath;
    }
    public void setManPackageNameFilePath(String manPackageNameFilePath) {
        this.manPackageNameFilePath = manPackageNameFilePath;
    }
    public String getStudentPackageNameFilePath() {
        return studentPackageNameFilePath;
    }
    public void setStudentPackageNameFilePath(String studentPackageNameFilePath) {
        this.studentPackageNameFilePath = studentPackageNameFilePath;
    }
    public String getInternetuserPackageNameFilePath() {
        return internetuserPackageNameFilePath;
    }
    public void setInternetuserPackageNameFilePath(String internetuserPackageNameFilePath) {
        this.internetuserPackageNameFilePath = internetuserPackageNameFilePath;
    }
}
  1. 配置文件app.properties
woman.packagename.file.path=/data0/test/userInfo_confirm/woman_packageName.txt

man.packagename.file.path=/data0/test/userInfo_confirm/man_packageName.txt

student.packagename.file.path=/data0/test/userInfo_confirm/student_packageName.txt

internetuser.packagename.file.path=/data0/test/userInfo_confirm/internetuser_packageName.txt
  1. applicationContext.xml设置服务器启动加载配置文件
#单个配置文件写法
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="location">
            <value>classpath:server.properties</value>
        </property>
        <property name="fileEncoding" value="utf-8" />
    </bean>
#多个配置文件写法
<bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath:server.properties</value>
                <value>classpath:app.properties</value>
            </list>
        </property>
        <property name="fileEncoding" value="utf-8" />
    </bean>
  1. 调用配置文件属性
@Autowired
private FilePathConfig filePathConfig;
filePathConfig.getXXX()调用;

再接再厉!

border="0" width="330" height="86" src="http://music.163.com/outchain/player?type=2&id=28427765&auto=1&height=66">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值