package com.gzlh.bus; import cn.hutool.core.io.FileUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.XML; import com.gzlh.config.dto.ApplicationConfigDTO; import com.gzlh.config.dto.CaputreSetting; import com.gzlh.config.dto.EventDTO; import com.gzlh.config.dto.SerialSetting; import lombok.Data; import lombok.extern.slf4j.Slf4j; import java.io.File; import java.util.List; import java.util.Properties; @Data @Slf4j public class SysConfig { public static List eventDTOList; public static SerialSetting serialSetting; public static CaputreSetting caputreSetting; public static void initConfig() { Properties properties = System.getProperties(); String rootPath = properties.getProperty("user.dir"); String separator = File.separator; String configFile = rootPath + separator + "config.xml"; if (!FileUtil.exist(configFile)) { log.error("配置文件不存在:{}", configFile); return; } String content = FileUtil.readUtf8String(configFile); JSONObject result = XML.toJSONObject(content); log.info("result:{}",result.toJSONString(0)); ApplicationConfigDTO configDTO = result.toBean(ApplicationConfigDTO.class); eventDTOList=configDTO.getConfig().getEventList().getEvent(); serialSetting=configDTO.getConfig().getSysConfig().getSerialSetting(); caputreSetting=configDTO.getConfig().getSysConfig().getCaputreSetting(); } }