|
@@ -7,18 +7,28 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import com.dgtly.common.utils.StringUtils;
|
|
|
import com.dgtly.common.utils.YamlUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
|
* 全局配置类
|
|
|
*
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
+@Component
|
|
|
public class Global
|
|
|
{
|
|
|
private static final Logger log = LoggerFactory.getLogger(Global.class);
|
|
|
|
|
|
- private static String DEFULT_NAME = "application.yml";
|
|
|
|
|
|
+ private static String active ;
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ public void setActive(String active) {
|
|
|
+ Global.active = active;
|
|
|
+ }
|
|
|
/**
|
|
|
* 当前对象实例
|
|
|
*/
|
|
@@ -56,7 +66,7 @@ public class Global
|
|
|
Map<?, ?> yamlMap = null;
|
|
|
try
|
|
|
{
|
|
|
- yamlMap = YamlUtil.loadYaml(getConfigeFileName());
|
|
|
+ yamlMap = YamlUtil.loadYaml("application-"+active+".yml");
|
|
|
value = String.valueOf(YamlUtil.getProperty(yamlMap, key));
|
|
|
map.put(key, value != null ? value : StringUtils.EMPTY);
|
|
|
}
|
|
@@ -140,18 +150,5 @@ public class Global
|
|
|
return getProfile() + "/upload";
|
|
|
}
|
|
|
|
|
|
- public static String getConfigeFileName(){
|
|
|
- String value="";
|
|
|
- Map<?, ?> yamlMap = null;
|
|
|
- try
|
|
|
- {
|
|
|
- yamlMap = YamlUtil.loadYaml(DEFULT_NAME);
|
|
|
- value = String.valueOf(YamlUtil.getProperty(yamlMap, "spring.profiles.active"));
|
|
|
- }
|
|
|
- catch (FileNotFoundException e)
|
|
|
- {
|
|
|
- log.error("获取全局配置异常 ");
|
|
|
- }
|
|
|
- return "application-"+value+".yml";
|
|
|
- }
|
|
|
+
|
|
|
}
|