From 85446b5b526ac53af9add7c83cfd72f39ec39611 Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期五, 07 七月 2023 10:51:13 +0800 Subject: [PATCH] 优化外联设备报警解析并上传mqtt --- src/main/java/com/ard/utils/SpringTool.java | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/ard/utils/SpringTool.java b/src/main/java/com/ard/utils/SpringTool.java index 0a7acfb..123317b 100644 --- a/src/main/java/com/ard/utils/SpringTool.java +++ b/src/main/java/com/ard/utils/SpringTool.java @@ -1,11 +1,15 @@ package com.ard.utils; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; import java.nio.ByteBuffer; +import java.util.Properties; /** * @Description: @@ -36,4 +40,18 @@ return getApplicationContext().getBean(name); } + /*yml閰嶇疆淇℃伅鑾峰彇*/ + public static String getYmlInfo(String key) { + Resource resource = new ClassPathResource("application.yml"); + Properties properties = null; + try { + YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean(); + yamlFactory.setResources(resource); + properties = yamlFactory.getObject(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + return properties.get(key).toString(); + } } \ No newline at end of file -- Gitblit v1.9.3