BeisenParamByPropertiesUtil.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.kingdee.eas.custom.beisen.utils;
  2. import com.google.common.collect.Maps;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.apache.log4j.Logger;
  5. import java.io.FileInputStream;
  6. import java.io.IOException;
  7. import java.util.Map;
  8. import java.util.Properties;
  9. import java.util.Set;
  10. /**
  11. * 获取配置文件参数值
  12. * description: BeisenParamByProperties <br>
  13. * date: 2025/7/7 16:03 <br>
  14. * author: lhbj <br>
  15. * version: 1.0 <br>
  16. */
  17. public class BeisenParamByPropertiesUtil {
  18. private static Logger logger =Logger.getLogger(BeisenParamByPropertiesUtil.class);
  19. private Properties propt = new Properties();//共用参数
  20. /**
  21. * filePath地址从server开始,例:/server/properties/beisen/beisenConfig.properties
  22. * @param filePath
  23. */
  24. public BeisenParamByPropertiesUtil(String filePath) throws IOException {
  25. this.initConfig(System.getProperty("EAS_HOME") + filePath);
  26. }
  27. public BeisenParamByPropertiesUtil() throws IOException {
  28. }
  29. public BeisenParamByPropertiesUtil initConfig(String filePath) throws IOException {
  30. try {
  31. if(StringUtils.isBlank(filePath)){
  32. throw new IOException("filePath参数为空");
  33. }
  34. this.propt.load(new FileInputStream(filePath));
  35. return this;
  36. }catch (IOException e){
  37. e.printStackTrace();
  38. logger.error("未找到"+filePath+"配置文件。");
  39. throw e;
  40. }
  41. }
  42. public Map<String,String> getConfig() {
  43. Map<String,String> map = Maps.newHashMap();
  44. Set<Map.Entry<Object, Object>> set = this.propt.entrySet();
  45. for(Map.Entry<Object, Object> entry : set){
  46. map.put((String)entry.getKey(),(String)entry.getValue());
  47. }
  48. return map;
  49. }
  50. }