配置文件的读取 java

 

//读取文件工具类


package com.ane.wechat.common.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


 
public class PropertiesUtils {

    private static final Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);
    
    private static Properties props;
    
    static{
        loadProps();
    }

    synchronized static void loadProps() {
        logger.info("属性文件类容开始加载");
        props = new Properties();
        InputStream is = null;
        try {
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream("config.properties");
            props.load(is);
        } catch (IOException e) {
            logger.error("读取配置文件:config.properties 出现异常");
        }finally{
            if (is != null){
                try {
                    is.close();
                } catch (IOException e) {
                    logger.error("读取配置文件:config.properties关闭流出现异常");
                }
            }
        }
    }
    
    /**
     * 按照key值加载属性值
     * @param key
     * @return
     */
    public static String getProperty(String key){
        if (null == props){
            loadProps();
        }
        return props.getProperty(key);
    }
    
    /**
     * 按照key值加载属性值 可以指定默认值
     * @param key
     * @param defaultValue
     * @return
     */
    public static String getProperty(String key, String defaultValue){
        if (null == props){
            loadProps();
        }
        return props.getProperty(key, defaultValue);
    }
    
}

 

 

 

//配置文件

#\u5FEB\u8FD0\u4E0B\u5355\u63A5\u53E3
aneop.server.url=http://101.95.139.62:40144/aneop/

aneop.server.AppSecret=732e4925432b31c41d1ec0665114c97d
aneop.server.creatOrder_code=ANEGW_KD
aneop.server.creatOrder_action=express/websiteEx/new

aneop.server.creatOrder2_code=ANEGW_KY
aneop.server.creatOrder2_action=op/general/new

aneop.server.cancel_code=ANEGW_KY
aneop.server.cancel_action=op/general/cancel

aneop.server.logisticsQuery_code=ANEWX
aneop.server.logisticsQuery_diagest_code=9296a9b3790d6ac25f143af5e45fb226
aneop.server.logisticsQuery_action=services/logisticsQuery/query

#duan xin yan zheng ma
anesms.server.url=http://10.230.32.161:8080/anesms/sendsm
anesms.server.sendsm_code=anegw
aneop.server.sendsm_key=TGBHYRFVERTY



#GIS Http SERVICE
#gis.server.productAddress=http://ditu.ane56.com/ws/gisServerRest/gisserver/operate
#gis.server.productKey=ane_express
#gis.server.productSecret=f243f636bce4ad4da764b088edd98ac9


#kuaidi server
gis.server.ky_address=http://192.168.1.119:8081/ane56_gis/ws/gisServerRest/gisserver/operate
gis.server.ky_Key=ane_express
gis.server.ky_secret=111111

gis.server.type=wsDetailedMatchServiceImpl
#kuai yun server
gis.server.kd_address=http://101.95.139.62:40110/ws/gisServerRest/gisserver/operate
gis.server.kd_key=ane_express
gis.server.kd_secret=111111



 

 

//读取文件

 

 

package com.ane.wechat.business.utils;

import com.ane.wechat.common.utils.PropertiesUtils;
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;

public class Constants {
    // 第三方用户唯一凭证
     public static String appid;
     // 第三方用户唯一凭证密钥
     public static String appsecret;
    
     /**
      * 写在代码里面,容易遗漏修改,需要改为从配置获取
      */
     static{
         appid = Weixin4jConfigUtil.getWeixinAccount().getId();
         appsecret = Weixin4jConfigUtil.getWeixinAccount().getSecret();
         //初始化GIS服务常量
        GIS_KY= PropertiesUtils.getProperty("gis.server.ky_address");
        GIS_KY_KEY = PropertiesUtils.getProperty("gis.server.ky_Key");
        GIS_KY_SECRET = PropertiesUtils.getProperty("gis.server.ky_secret");
        GIS_KY_TYPE = PropertiesUtils.getProperty("gis.server.type");
        GIS_KD= PropertiesUtils.getProperty("gis.server.kd_address");
        GIS_KD_KEY = PropertiesUtils.getProperty("gis.server.kd_key");
        GIS_KD_SECRET = PropertiesUtils.getProperty("gis.server.kd_secret");
        GIS_KD_TYPE = PropertiesUtils.getProperty("gis.server.type");

     }

    
     public static String Vcode=null;
     //当前页
    // public static int currentPage;
     //官微下单数量
     public static int getGwTotal;
    
     //官网快递注册
     public static String KDregister_URL="http://101.95.139.62:9876/WxUser/registerByPhone";
    
    //官网快运注册
     public static String KYregister_URL="http://101.95.139.62:9873/WxUser/registerByPhone";
    
    //官网快递查单
     public static String KDquery_URL="http://101.95.139.62:9876/WxUser/queryOrder";
    
    //官网快运查单
     public static String KYquery_URL="http://101.95.139.62:9873/WxUser/queryOrder";
    
    
    //开放平台快递下单
     public static String ANEGW_KD_URL="http://101.95.139.62:40144/aneop/express/websiteEx/new";
    //开放平台快递下单code
    public static String ANEGW_KD_CODE="ANEGW_KD";
     //开放平台快递下单密钥
     public static String ANEGW_KD_appsecret="732e4925432b31c41d1ec0665114c97d";
    
    
     //开放平台快运下单
     public static String ANEGW_KY_URL="http://101.95.139.62:40144/aneop/op/general/new";
    //开放平台快运下单code
    public static String ANEGW_KY_CODE="ANEGW_KY";
     //开放平台快运下单密钥
     public static String ANEGW_KY_appsecret="ef2849f99b44671b9e5085e44b45a450";
    
    
     //开放平台运单查询
     public static String ANEWX_QUERY_URL="http://101.95.139.62:40144/aneop/services/logisticsQuery/query";
    //开放平台运单查询code
     public static String ANEWX_QUERY_CODE="ANEWX";
     //开放平台运单查询密钥
     public static String ANEWX_QUERY_appsecret="9296a9b3790d6ac25f143af5e45fb226";
    
    
     //开放平台快运撤销
     public static String KY_Cancle_URL="http://101.95.139.62:40144/aneop/op/general/cancel";
    //开放平台快运撤销code
    public static String KY_Cancle_CODE="ANEGW_KY";
    //开放平台快运撤销密钥
    public static String KY_Cancle_appsecret="ef2849f99b44671b9e5085e44b45a450";
    
    
     //短信平台
     public static String SMS_URL="http://10.230.32.161:8080/anesms/sendsm";
     //短信平台的code
     public static String SMS_CODE="anegw";
     //短信平台的密钥
     public static String SMS_appsecret="TGBHYRFVERTY";
    
     /**
      * 快运接口相关常量配置 服务地址 key secret 类型
      */
    public static String GIS_KY;
    
    public static String GIS_KY_KEY;
    
    public static String GIS_KY_SECRET;

    public static String GIS_KY_TYPE;
    
     /**
      * 快递接口相关常量配置 服务地址 key secret 类型
      */
    public static String GIS_KD;
    
    public static String GIS_KD_KEY;
    
    public static String GIS_KD_SECRET;

    public static String GIS_KD_TYPE;

    
}

 

posted @ 2017-05-22 17:59  蓝火延枫  阅读(479)  评论(0编辑  收藏  举报