spring 将配置文件中的值注入 属性
1、编写配置文件
#债权转让#默认周期 必须大于0credit.defaultDuration=1#最小转让金额(元)credit.minBidAmount=1.00#最小转让时间 到期时间小于此的不让进行转让(小时)credit.assignThreshold=24#最小折让率(%)credit.minDiscountRate=70#最大折让率(%)credit.maxDiscountRate=110
<!-- 配置参数 --><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>
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 $*/@Componentpublic 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;}}
model.put("defaultDuration", Constant.getDefaultDuration());model.put("minDiscountRate", Constant.getMinDiscountRate());model.put("maxDiscountRate", Constant.getMaxDiscountRate());
spring 将配置文件中的值注入 属性的更多相关文章
- 将springboot配置文件中的值注入到静态变量
SpringBoot配置文件分为.properties和.yml两种格式,根据启动环境的不同获取不同环境的的值. spring中不支持直接注入静态变量值,利用spring的set注入方法注入静态变量 ...
- springboot属性类自动加载配置文件中的值
springboot属性类自动加载配置文件中的值,如Person类加载在yml中配置的name,age等属性值,可以通过如下步骤获取: 类上添加@ConfigurationProperties注解,p ...
- struts2配置文件中action的name属性
struts2配置文件中action的name属性的第一个字符不要加斜杠 <action name="see" class="baoxiuManage_seeAct ...
- ThinkPHP 获取配置文件中的值
C('SPECIAL_USER'):获取配置文件中的值 存入数组
- spring读取classpath目录下的配置文件通过表达式去注入属性值.txt
spring读取配置文件: 1. spring加载配置文件: <context:property-placeholder location="classpath:config/syst ...
- 配置文件中取值: spring配置文件中util:properties和context:property-placeholder
转载大神 https://blog.csdn.net/n447194252/article/details/77498916 util:properties和context:property-plac ...
- spring 3配置文件中如何注入map list set等类型
首先写个 javabean类吧,如下 package com.bean; import java.util.List; import java.util.Map; import java.util.P ...
- 日志配置文件读取spring boot配置文件中的属性
如果是读取 application.properties 这种spring boot的默认配置文件时 其中 scope固定为context 指明从上下文中获取, name 根据自己的意思给, sou ...
- Spring根据XML配置文件 p名称空间注入属性(property后出现,简便但只针对基本数据类型管用,自定义集合等引用类型无效)
要生成对象并通过名称空间注入属性的类 代码如下: package com.swift; public class User { private String userName; public void ...
随机推荐
- git远程上传文件
[第一步]建立先仓库 第一步的话看一般的提示就知道了,在github新建一个repository(谷歌可以解决),都是可视化的界面操作,所以难度不大.或者看这里:https://help.github ...
- 进入DRF和ANGULAR的整合学习,这三篇入门内容一定要学好的
看来,DJANGO的模板功能是无法用啦, 学着用ANGLUAR的SERVICE,MODULE,CONTROLLER啦... http://engineroom.trackmaven.com/blog/ ...
- 17、Java并发性和多线程-避免死锁
以下内容转自http://ifeve.com/deadlock-prevention/: 在有些情况下死锁是可以避免的.本文将展示三种用于避免死锁的技术: 加锁顺序 当多个线程需要相同的一些锁,但是按 ...
- Animations动画和Keyframes关键帧
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 符号变换引擎(Symbol Transform Engine - STE)
在写编译器的过程中.我意识到编译事实上是一种符号变换,比方C语言编译成机器码,事实上是C源代码文件里的符号变换成EXE的16进制符号,这和中文翻译成英语的语言翻译器没什么差别. 每一个程序猿都有自己喜 ...
- 46.Android 自己定义Dialog
46.Android 自己定义Dialog Android 自己定义Dialog 前言 提示Dialog 提示Dialog 效果图 菜单Dialog 菜单Dialog 效果图 DialogActivi ...
- Linux声卡驱动移植和測试
一.分析驱动程序,依据开发板改动代码 代码太长,就不贴了,几个注意点: 1. 查看开发板原理图和S3C2410的datasheet,UDA1341的L3MODE.L3DATA.L3CLOCK分别与S3 ...
- cocos2D(七)---- CCScene
CCScene普通情况是游戏里面的根节点.称之为"场景",执行游戏时须要通过CCDirector启动第一个场景. 当然,游戏略微复杂一点的话.可能会包括非常多个场景,这就涉及到场景 ...
- Unity编程笔录--ulua+PureMVC框架简单热更新使用
ulua+PureMVC框架简单热更新使用 前言: 1:作者官网论坛 首先介绍的是这个框架是一位大牛 骏擎[CP] jarjin 写的,据说原本是"非常多人不知道怎么使用Ulua,所 ...
- poj 3020 Antenna Placement(二分无向图 匈牙利)
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6438 Accepted: 3176 ...