diff --git a/pom.xml b/pom.xml
index aaf2ee6..6c21c1d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -493,4 +493,40 @@
+
+
+
+ local
+
+ local
+ local
+
+
+ true
+
+
+
+
+ dev
+
+ dev
+ dev
+
+
+ false
+
+
+
+
+
+ prod
+
+ prod
+ prod
+
+
+ false
+
+
+
diff --git a/src/main/java/egovframework/EgovBootApplication.java b/src/main/java/egovframework/EgovBootApplication.java
index 914d47a..7ec53f2 100644
--- a/src/main/java/egovframework/EgovBootApplication.java
+++ b/src/main/java/egovframework/EgovBootApplication.java
@@ -29,7 +29,7 @@ public class EgovBootApplication {
);
public static void main(String[] args) {
- log.debug("##### EgovBootApplication Start #####");
+ log.debug("##### EgovBootApplication::active profiles - {} Start #####", System.getProperty("spring.profiles.active"));
// SpringApplication springApplication = new SpringApplication(EgovBootApplication.class);
@@ -56,7 +56,7 @@ public class EgovBootApplication {
- log.debug("##### EgovBootApplication End #####");
+ log.debug("##### EgovBootApplication::active profiles - {} End #####", System.getProperty("spring.profiles.active"));
}
}
diff --git a/src/main/java/egovframework/com/cmm/service/EgovProperties.java b/src/main/java/egovframework/com/cmm/service/EgovProperties.java
index 5e84dc3..08ecbf8 100644
--- a/src/main/java/egovframework/com/cmm/service/EgovProperties.java
+++ b/src/main/java/egovframework/com/cmm/service/EgovProperties.java
@@ -50,64 +50,14 @@ public class EgovProperties {
//파일구분자
static final char FILE_SEPARATOR = File.separatorChar;
-
- //프로퍼티 파일의 물리적 위치
- /*public static final String GLOBALS_PROPERTIES_FILE
- = System.getProperty("user.home") + System.getProperty("file.separator") + "egovProps"
- + System.getProperty("file.separator") + "globals.properties";*/
-
- // 프로퍼티 파일의 위치 prefix
- // /target/classes/egovframework
- //public static final String RELATIVE_PATH_PREFIX = "classpath:" + FILE_SEPARATOR + "egovframework";
-
- // 프로퍼티 파일의 위치
- // /target/classes/egovframework/egovProps/globals.properties
- //public static final String GLOBALS_PROPERTIES_FILE = RELATIVE_PATH_PREFIX + FILE_SEPARATOR +"egovProps"+ FILE_SEPARATOR + "globals.properties";
-
- // /target/classes/application.properties
- //public static final String GLOBALS_PROPERTIES_FILE = "classpath:" + FILE_SEPARATOR + "application.properties";
-
+
// egovframework/com/cmm/service -> /../../../../ 경로에 properties
public static final String RELATIVE_PATH_PREFIX = EgovProperties.class.getResource("").getPath()
+ FILE_SEPARATOR + ".." + FILE_SEPARATOR
+ ".." + FILE_SEPARATOR + ".." + FILE_SEPARATOR + ".." + FILE_SEPARATOR;
public static final String GLOBALS_PROPERTIES_FILE
- = RELATIVE_PATH_PREFIX + "application.properties";
-
- /**
- * 인자로 주어진 문자열을 Key값으로 하는 상대경로 프로퍼티 값을 절대경로로 반환한다(Globals.java 전용)
- * @param keyName String
- * @return String
-
- public static String getPathProperty(String keyName){
- String value = ERR_CODE;
- value="99";
- debug(GLOBALS_PROPERTIES_FILE + " : " + keyName);
- FileInputStream fis = null;
- try{
- Properties props = new Properties();
- fis = new FileInputStream(GLOBALS_PROPERTIES_FILE);
- props.load(new java.io.BufferedInputStream(fis));
- value = props.getProperty(keyName).trim();
- value = RELATIVE_PATH_PREFIX + "egovProps" + System.getProperty("file.separator") + value;
- }catch(FileNotFoundException fne){
- debug(fne);
- }catch(IOException ioe){
- debug(ioe);
- }catch(Exception e){
- debug(e);
- }finally{
- try {
- if (fis != null) fis.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- }
- return value;
- }
- */
+ = RELATIVE_PATH_PREFIX + "application.yml";
/**
* 인자로 주어진 문자열을 Key값으로 하는 프로퍼티 값을 반환한다(Globals.java 전용)
@@ -140,56 +90,7 @@ public class EgovProperties {
}
return value;
- /*
- Resource resources = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader())
- .getResource(GLOBALS_PROPERTIES_FILE);
-
- debug(GLOBALS_PROPERTIES_FILE + " : " + keyName);
-
- try (InputStream in = resources.getInputStream()) {
- Properties props = new Properties();
- props.load(new java.io.BufferedInputStream(in));
- if ( props.getProperty(keyName) != null )
- value = props.getProperty(keyName).trim();
- } catch (FileNotFoundException fne) {
- debug(fne);
- } catch (IOException ioe) {
- debug(ioe);
- }
- return value;
- */
- }
-
- /**
- * 주어진 파일에서 인자로 주어진 문자열을 Key값으로 하는 프로퍼티 상대 경로값을 절대 경로값으로 반환한다
- * @param fileName String
- * @param key String
- * @return String
-
- public static String getPathProperty(String fileName, String key){
- FileInputStream fis = null;
- try{
- java.util.Properties props = new java.util.Properties();
- fis = new FileInputStream(fileName);
- props.load(new java.io.BufferedInputStream(fis));
- fis.close();
-
- String value = props.getProperty(key);
- value = RELATIVE_PATH_PREFIX + "egovProps" + System.getProperty("file.separator") + value;
- return value;
- }catch(java.io.FileNotFoundException fne){
- return ERR_CODE_FNFE;
- }catch(java.io.IOException ioe){
- return ERR_CODE_IOE;
- }finally{
- try {
- if (fis != null) fis.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
}
- */
/**
* 주어진 파일에서 인자로 주어진 문자열을 Key값으로 하는 프로퍼티 값을 반환한다
@@ -264,34 +165,6 @@ public class EgovProperties {
debug("EX:"+ex);//ex.printStackTrace();
}
}
- /*
- String src = EgovWebUtil.filePathBlackList(property.replace("\\", FILE_SEPARATOR).replace("/", FILE_SEPARATOR));
- try (FileInputStream fis = new FileInputStream(src)) {
-
- File srcFile = new File(src);
- if (srcFile.exists()) {
-
- java.util.Properties props = new java.util.Properties();
- props.load(new java.io.BufferedInputStream(fis));
-
- int i = 0;
- Enumeration> plist = props.propertyNames();
- if (plist != null) {
- while (plist.hasMoreElements()) {
- Map map = new HashMap();
- String key = (String)plist.nextElement();
- map.put(key, props.getProperty(key));
- keyList.add(map);
- }
- }
- }
- } catch (FileNotFoundException ex) {
- debug("FileNotFoundException:" + ex);
- } catch (IOException ex) {
- debug("IOException:" + ex);
- }
-
- */
return keyList;
}
diff --git a/src/main/java/egovframework/com/cmm/service/EgovYmlProperties.java b/src/main/java/egovframework/com/cmm/service/EgovYmlProperties.java
new file mode 100644
index 0000000..9e9139e
--- /dev/null
+++ b/src/main/java/egovframework/com/cmm/service/EgovYmlProperties.java
@@ -0,0 +1,130 @@
+package egovframework.com.cmm.service;
+
+import lombok.extern.slf4j.Slf4j;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+@Slf4j
+public class EgovYmlProperties {
+
+ // 에러 메시지 상수
+ public static final String ERR_CODE = "EXCEPTION OCCURRED";
+
+ // YAML 파일 경로
+ public static final String GLOBALS_YAML_FILE = "application.yml";
+
+ // 활성 프로파일 설정 (기본값은 "default")
+ private static final String ACTIVE_PROFILE = System.getProperty("spring.profiles.active", "local");
+
+ /**
+ * 인자로 주어진 키에 해당하는 값을 반환한다.
+ * @param keyName String
+ * @return String
+ */
+ public static String getProperty(String keyName) {
+ try (InputStream baseInputStream = EgovProperties.class.getClassLoader().getResourceAsStream(GLOBALS_YAML_FILE);
+ InputStream profileInputStream = EgovProperties.class.getClassLoader().getResourceAsStream(getProfileYamlFile())) {
+
+ Yaml yaml = new Yaml();
+
+ // 기본 YAML 읽기
+ Map yamlMap = baseInputStream != null ? yaml.load(baseInputStream) : new HashMap<>();
+
+ // 프로파일별 YAML 읽기 (override)
+ if (profileInputStream != null) {
+ Map profileMap = yaml.load(profileInputStream);
+ yamlMap.putAll(profileMap);
+ }
+
+ return getValueFromYamlMap(yamlMap, keyName);
+ } catch (Exception e) {
+ log.error("YAML 읽기 오류: {}", e.getMessage(), e);
+ return ERR_CODE;
+ }
+ }
+
+ /**
+ * 중첩된 YAML 구조에서 키로 값을 찾는다.
+ * @param yamlMap Map
+ * @param keyName String
+ * @return String
+ */
+ @SuppressWarnings("unchecked")
+ private static String getValueFromYamlMap(Map yamlMap, String keyName) {
+ String[] keys = keyName.split("\\.");
+ Object current = yamlMap;
+ for (String key : keys) {
+ if (current instanceof Map) {
+ current = ((Map) current).get(key);
+ } else {
+ return ERR_CODE; // 키 경로가 잘못된 경우
+ }
+ }
+ return Objects.toString(current, ERR_CODE);
+ }
+
+ /**
+ * YAML 파일의 내용을 key-value 형태의 리스트로 반환한다.
+ * @return List