首先在spring配置文件applicationContext.xml中配置、

    <bean id="placeholderConfig"
class="com.beikbank.common.utils.PropertyConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:redis.properties</value>
<value>classpath:SysConfig.properties</value>
</list>
</property>
</bean>

如果我们要在代码中使用SysConfig.properties中配置信息,我们可以自己写个类PropertyConfigurer继承PropertyPlaceholderConfigurer·

public class PropertyConfigurer extends PropertyPlaceholderConfigurer {

    private static Map<String, String> propertyMap;

    @Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess, props);
propertyMap = new HashMap<>();
for (Object key : props.keySet()) {
String keyStr = key.toString();
String value = props.getProperty(keyStr);
propertyMap.put(keyStr, value);
}
} public static String getProperty(String name) {
return propertyMap.get(name);
} /**
* 返回propertyMap
*
* @return
*/
public static Map<String, String> getPropertyMap() {
return propertyMap;
}
}

这样把属性值在系统启动的时候就设进去可以后续直接调用静态方法了

配置文件properties读取使用的好方法的更多相关文章

  1. properties读取的几种方法

    第一种: private static Properties prop = new Properties();     static{         try {             prop.l ...

  2. spring boot: 从配置文件中读取数据的常用方法(spring boot 2.3.4)

    一,从配置文件中读取数据有哪些方法? 通常有3种用法: 1,直接使用value注解引用得到配置项的值 2,  封装到Component类中再调用 3,  用Environment类从代码中直接访问 生 ...

  3. java分享第十六天( java读取properties文件的几种方法&java配置文件持久化:static块的作用)

     java读取properties文件的几种方法一.项目中经常会需要读取配置文件(properties文件),因此读取方法总结如下: 1.通过java.util.Properties读取Propert ...

  4. Java配置文件Properties的读取、写入与更新操作

    /** * 实现对Java配置文件Properties的读取.写入与更新操作 */ package test; import java.io.BufferedInputStream; import j ...

  5. 对Java配置文件Properties的读取、写入与更新操作

    http://breezylee.iteye.com/blog/1340868 对Java配置文件Properties的读取.写入与更新操作 博客分类: javase properties  对Jav ...

  6. 实现对Java配置文件Properties的读取、写入与更新操作

    /** * 实现对Java配置文件Properties的读取.写入与更新操作 */ package test; import java.io.BufferedInputStream; import j ...

  7. Properties读取properties配置文件

    package cn.rocker.readProperties; import java.io.IOException; import java.io.InputStream; import jav ...

  8. ResourceBundle与Properties读取配置文件

    ResourceBundle与Properties的区别在于ResourceBundle通常是用于国际化的属性配置文件读取,Properties则是一般的属性配置文件读取. ResourceBundl ...

  9. 读取配置文件properties的几种方式

    介绍几种读取方式:参考:https://www.cnblogs.com/sebastian-tyd/p/7895182.html .基于ClassLoder读取配置文件 注意:该方式只能读取类路径下的 ...

随机推荐

  1. c语言中的register int

    register int a=1; 明确声明必须要把变量存放在寄存器中,直到变量消失. 一般是默认register,大多数的情况下是不用写register

  2. ASP.NET Core 入门

    关于ASP.NET Core ASP.NET Core 是一个全新的开源.跨平台框架,可以用它来构建基于网络连接的现代云应用程序,比如:Web 应用,IoT(Internet Of Things,物联 ...

  3. 微信小程序项目踩过的几个坑

    一.前言 近期,开始了一段辛酸的还未开始就已经结束的"创业"(参见我的第二次创业,以梦为马,莫负韶华).大体上是开发了一款微信小程序,关于创业这件事情就不细说了,本文主要介绍一下开 ...

  4. python中的string

    也可以用一个变量来保存字符串,然后输出str = ‘bad’print str 如果你想表示一段带有英文单引号或者双引号的文字,那么表示这个字符串的引号就要与内容区别开. 内容带有单引号,就用双引号表 ...

  5. python中的变量,运算符

    范例: name = 'Crossin' myVar = 123 price = 5.99 visible = True “=”的作用是把右边的值赋予给左边的变量. python中有四种较为常见的数据 ...

  6. 搭建SS服务器

    体验: http://ss.ishadowx.com/ centos7 安装shadowsocks客户端 http://blog.csdn.net/guyan0319/article/details/ ...

  7. DxPackNet 2.视频截图和捕捉帧图片

    在上一节的基础上 打开了摄像头后: 1.视频截图------调用  CatchBmp 方法即可获取当前帧的 bmp 图像, //调用截屏函数 获取当前图片 Bitmap bmp = camCaptur ...

  8. python数据可视化学习1

    import matplotlib.pyplot as plt input_values = [1,2,3,4,5] #输入值 squares = [1,4,9,16,25] #输出值 plt.plo ...

  9. HDU - 1846 Brave Game 巴什博弈

    思路:直接判断n是不是m+1的倍数,若是先手则输,否则赢. AC代码 #include <cstdio> #include <cmath> #include <algor ...

  10. 关于Spring事务的原理,以及在事务内开启线程,连接池耗尽问题.

    主要以结果为导向解释Spring 事务原理,连接池的消耗,以及事务内开启事务线程要注意的问题. Spring 事务原理这里不多说,网上一搜一大堆,也就是基于AOP配合ThreadLocal实现. 这里 ...