微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SystemProperties读取资源文件.properties文件的配置属性

SystemProperties.java属性类是读取src下面的visaManagement.properties配置文件,具体如下所示:

 

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

import org.apache.log4j.Logger;

/**
 * 系统配置文件
 *
 */
public class SystemProperties {

 //日志
 private static Logger logger = Logger.getLogger(SystemProperties.class);
 
 private static Properties systemProperties = new Properties();
 
 /**
  * 报文发送地址URL
  */
 
 public static final String WEBSERVICE_URL = "webService.url";
 
 /**
  * 是否加密
  */
 public static final String IS_ENCRYPT = "isEncrypt";
 
 /**
  * 报表存放路径
  */
 public static final String  REPORT_DIR= "report.dir";
 
 /**
  * 报表文件类型
  */
 public static final String FILE_TYPE = "file.type";
 
 static{
  try {
   systemProperties.load(SystemProperties.class.getResourceAsstream("/visaManagement.properties"));
  } catch (IOException e) {
   logger.error("加载system.properties文件失败");
   e.printstacktrace();
  }
  
 }
 
 /**
  * 从.properties文件中得到相应属性的值
  */
 public static String getProperty(String property){
  return systemProperties.getProperty(property);
 }
 
}

 

visaManagement.properties配置文件如下所示:

 

webService.url=http://120.21.210.21:8080/service

isEncrypt = true
#isEncrypt = false

#----Path of report
report.dir = D:/workspaces/gpicSpace/e-cargo/cargo-online/template

file.type = .jasper

ip = 000000000000006

 

 

在其他地方想要获得visaManagement.properties配置文件中的某个参数的值可调用SystemProperties.getProperty("ip")来获得

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐