全局配置类修改为注解,防止多环境配置下读取问题。

master
RuoYi 5 years ago committed by Limy
parent eee0dee0f9
commit 143456a779

@ -1,119 +1,93 @@
package com.ruoyi.common.config; package com.ruoyi.common.config;
import java.io.FileNotFoundException; import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.HashMap; import org.springframework.stereotype.Component;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.YamlUtil;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
@Component
@ConfigurationProperties(prefix = "ruoyi")
public class Global 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 String copyrightYear;
*/
private static Global global;
/** /** 实例演示开关 */
* private static boolean demoEnabled;
*/
private static Map<String, String> map = new HashMap<String, String>(); /** 上传路径 */
private static String profile;
private Global() /** 获取地址开关 */
private static boolean addressEnabled;
public static String getName()
{ {
return name;
} }
/** public void setName(String name)
*
*/
public static synchronized Global getInstance()
{ {
if (global == null) Global.name = name;
{
global = new Global();
}
return global;
} }
/** public static String getVersion()
*
*/
public static String getConfig(String key)
{ {
String value = map.get(key); return version;
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;
} }
/** public void setVersion(String version)
*
*/
public static String getName()
{ {
return StringUtils.nvl(getConfig("ruoyi.name"), "RuoYi"); Global.version = version;
} }
/** public static String getCopyrightYear()
*
*/
public static String getVersion()
{ {
return StringUtils.nvl(getConfig("ruoyi.version"), "4.1.0"); return copyrightYear;
} }
/** public void setCopyrightYear(String copyrightYear)
*
*/
public static String getCopyrightYear()
{ {
return StringUtils.nvl(getConfig("ruoyi.copyrightYear"), "2019"); Global.copyrightYear = copyrightYear;
} }
/** public static boolean isDemoEnabled()
*
*/
public static String isDemoEnabled()
{ {
return StringUtils.nvl(getConfig("ruoyi.demoEnabled"), "true"); return demoEnabled;
} }
/** public void setDemoEnabled(boolean demoEnabled)
* ip
*/
public static Boolean isAddressEnabled()
{ {
return Boolean.valueOf(getConfig("ruoyi.addressEnabled")); Global.demoEnabled = demoEnabled;
} }
/**
*
*/
public static String getProfile() 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;
} }
/** /**

Loading…
Cancel
Save