From 5346af9ab07fc428227d2dd981391e36ff24cbda Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 7 Nov 2019 17:33:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E9=85=8D=E7=BD=AE=E7=B1=BB?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=B3=A8=E8=A7=A3=EF=BC=8C=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=A4=9A=E7=8E=AF=E5=A2=83=E9=85=8D=E7=BD=AE=E4=B8=8B?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/common/config/Global.java | 126 +++++++----------- 1 file changed, 50 insertions(+), 76 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java index 391eb2f95..34a47fa0c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/Global.java @@ -1,119 +1,93 @@ package com.ruoyi.common.config; -import java.io.FileNotFoundException; -import java.util.HashMap; -import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.YamlUtil; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; /** * 全局配置类 * * @author ruoyi */ +@Component +@ConfigurationProperties(prefix = "ruoyi") public class Global { - private static final Logger log = LoggerFactory.getLogger(Global.class); + /** 项目名称 */ + private static String name; - private static String NAME = "application.yml"; + /** 版本 */ + private static String version; - /** - * 当前对象实例 - */ - private static Global global; + /** 版权年份 */ + private static String copyrightYear; - /** - * 保存全局属性值 - */ - private static Map map = new HashMap(); + /** 实例演示开关 */ + private static boolean demoEnabled; + + /** 上传路径 */ + private static String profile; - private Global() + /** 获取地址开关 */ + private static boolean addressEnabled; + + public static String getName() { + return name; } - /** - * 静态工厂方法 - */ - public static synchronized Global getInstance() + public void setName(String name) { - if (global == null) - { - global = new Global(); - } - return global; + Global.name = name; } - /** - * 获取配置 - */ - public static String getConfig(String key) + public static String getVersion() { - String value = map.get(key); - if (value == null) - { - Map yamlMap = null; - try - { - yamlMap = YamlUtil.loadYaml(NAME); - value = String.valueOf(YamlUtil.getProperty(yamlMap, key)); - map.put(key, value != null ? value : StringUtils.EMPTY); - } - catch (FileNotFoundException e) - { - log.error("获取全局配置异常 {}", key); - } - } - return value; + return version; } - /** - * 获取项目名称 - */ - public static String getName() + public void setVersion(String version) { - return StringUtils.nvl(getConfig("ruoyi.name"), "RuoYi"); + Global.version = version; } - /** - * 获取项目版本 - */ - public static String getVersion() + public static String getCopyrightYear() { - return StringUtils.nvl(getConfig("ruoyi.version"), "4.1.0"); + return copyrightYear; } - /** - * 获取版权年份 - */ - public static String getCopyrightYear() + public void setCopyrightYear(String copyrightYear) { - return StringUtils.nvl(getConfig("ruoyi.copyrightYear"), "2019"); + Global.copyrightYear = copyrightYear; } - /** - * 实例演示开关 - */ - public static String isDemoEnabled() + public static boolean isDemoEnabled() { - return StringUtils.nvl(getConfig("ruoyi.demoEnabled"), "true"); + return demoEnabled; } - /** - * 获取ip地址开关 - */ - public static Boolean isAddressEnabled() + public void setDemoEnabled(boolean demoEnabled) { - return Boolean.valueOf(getConfig("ruoyi.addressEnabled")); + Global.demoEnabled = demoEnabled; } - /** - * 获取文件上传路径 - */ public static String getProfile() { - return getConfig("ruoyi.profile"); + return profile; + } + + public void setProfile(String profile) + { + Global.profile = profile; + } + + public static boolean isAddressEnabled() + { + return addressEnabled; + } + + public void setAddressEnabled(boolean addressEnabled) + { + Global.addressEnabled = addressEnabled; } /**