工程中个性化配置文件处理方法类

此文章是基于  搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台

功能:properties文件加载、取得key对应的值

1. 处理类:ConfigHolder.java

 1 package com.ims.common;
 2 
 3 import java.util.ResourceBundle;
 4 
 5 /**
 6  * 工程中properties文件处理方法类
 7  */
 8 public class ConfigHolder {
 9     private static ResourceBundle bundle;
10     
11     /**
12      * 加载properties文件
13      */
14     private static void loadConfig() {
15         if(bundle == null) {
16             // 在class下有config.properties文件
17             bundle = ResourceBundle.getBundle("config");
18         }
19     }
20     
21     /**
22      * 取得properties文件中指定key的值
23      * @param key
24      * @return
25      */
26     public static String getValue(String key) {
27         loadConfig();
28         return bundle.getString(key);
29     }    
30 }
View Code


2. src下配置文件 config.properties,例如 :

log.file.name=ims.log


3. 通过调用 ConfigHolder.getValue(String key) 取得对应配置的值

原文地址:https://www.cnblogs.com/Mr-kevin/p/5560723.html