#债权转让
#默认周期 必须大于0
credit.defaultDuration=1
#最小转让金额(元)
credit.minBidAmount=1.00
#最小转让时间 到期时间小于此的不让进行转让(小时)
credit.assignThreshold=24
#最小折让率(%)
credit.minDiscountRate=70
#最大折让率(%)
credit.maxDiscountRate=110
2、配置 spring
<!-- 配置参数 -->
<bean id="configProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<value>file:${config.root}/admin-config.properties</value>
</property>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="properties" ref="configProperties" />
</bean>
3、编写 Java类
可以 注入 静态属性 ,方法 要非静态
package com.netfinworks.fax.admin.web.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.netfinworks.common.util.money.Money;
/**
* <p>
* 常量配置
*</p>
* @author weichunhe
* @version $Id: Constant.java, v 0.1 2015年5月28日 下午5:14:22 weichunhe Exp $
*/
@Component
public class Constant {
private Logger log = LoggerFactory.getLogger(getClass());
private static final String LOG_PREFIX = "从配置文件中注入常量==>";
/**
* 债权转让 默认周期 周期必须大于0
*/
private static int defaultDuration=1;
@Value("#{configProperties['credit.defaultDuration']}")
public void setDefaultDuration(String defaultDuration) {
try {
Constant.defaultDuration = Integer.valueOf(defaultDuration);
} catch (Exception e) {
log.error(LOG_PREFIX+"注入默认周期出错!"+defaultDuration,e);
}
}
/**
* 债权转让 最小转让时间 到期时间小于此的不让进行转让(毫秒)
*/
private static long assignThreshold = 24*60*60*1000;
@Value("#{configProperties['credit.assignThreshold']}")
public void setAssignThreshold(String assignThreshold) {
try {
Constant.assignThreshold = Long.valueOf(assignThreshold) * 60 * 60 *1000L;
} catch (Exception e) {
log.error(LOG_PREFIX+"注入 最小转让时间出错!"+assignThreshold,e);
}
}
/**
* 债权转让 最小转让金额(元)
*/
private static Money minBidAmount ;
@Value("#{configProperties['credit.minBidAmount']}")
public void setMinBidAmount(Money minBidAmount) {
Constant.minBidAmount = minBidAmount;
}
/**
* 债权转让最小折让率(%)
*/
private static int minDiscountRate = 0;
@Value("#{configProperties['credit.minDiscountRate']}")
public void setMinDiscountRate(String minDiscountRate) {
try {
Constant.minDiscountRate =Integer.valueOf(minDiscountRate);
} catch (Exception e) {
log.error(LOG_PREFIX+"注入最小折让率出错!"+minDiscountRate,e);
}
}
/**
* 债权转让最大折让率(%)
*/
private static int maxDiscountRate = 110;
@Value("#{configProperties['credit.maxDiscountRate']}")
public void setMaxDiscountRate(String maxDiscountRate) {
try {
Constant.maxDiscountRate =Integer.valueOf(maxDiscountRate);
} catch (Exception e) {
log.error(LOG_PREFIX+"注入最大折让率出错!"+maxDiscountRate,e);
}
}
public static int getMinDiscountRate() {
return minDiscountRate;
}
public static int getMaxDiscountRate() {
return maxDiscountRate;
}
public static long getAssignThreshold() {
return assignThreshold;
}
public static Money getMinBidAmount() {
return minBidAmount;
}
public static int getDefaultDuration() {
return defaultDuration;
}
}
4、使用
model.put("defaultDuration", Constant.getDefaultDuration());
model.put("minDiscountRate", Constant.getMinDiscountRate());
model.put("maxDiscountRate", Constant.getMaxDiscountRate());