Browse Source

월별 테이블 생성 로직에 데이터 소스를 가져와서 DB 커넥션하게 변경

jksong 4 years ago
parent
commit
0989f2db93

+ 22 - 0
src/main/java/com/lemon/lifecenter/scheduler/common/ApplicationContextServe.java

@@ -0,0 +1,22 @@
+package com.lemon.lifecenter.scheduler.common;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+
+@Component
+public class ApplicationContextServe implements ApplicationContextAware{
+    private static ApplicationContext applicationContext;
+    
+    @Override
+    public void setApplicationContext(ApplicationContext context) throws BeansException {
+        applicationContext = context;
+    }
+    
+    
+    public static ApplicationContext getApplicationContext() {
+        return applicationContext;
+    }
+}

+ 23 - 0
src/main/java/com/lemon/lifecenter/scheduler/common/PropertyUtil.java

@@ -0,0 +1,23 @@
+package com.lemon.lifecenter.scheduler.common;
+
+import org.springframework.context.ApplicationContext;
+
+public class PropertyUtil {
+    public static String getProperty(String propertyName) {
+        return getProperty(propertyName, null);
+    }
+    
+    public static String getProperty(String propertyName, String defaultValue) {
+        String value = defaultValue;
+        ApplicationContext applicationContext = ApplicationContextServe.getApplicationContext();
+        
+        if(applicationContext.getEnvironment().getProperty(propertyName) == null) {
+            
+        } else {
+            value = applicationContext.getEnvironment().getProperty(propertyName).toString();
+        }
+        
+        return value;
+    }
+}
+

+ 2 - 1
src/main/java/com/lemon/lifecenter/scheduler/controller/PushController.java

@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.lemon.lifecenter.scheduler.common.PropertyUtil;
 import com.lemon.lifecenter.scheduler.common.PushUtils;
 import com.lemon.lifecenter.scheduler.dto.DeviceInfoDTO;
 import com.lemon.lifecenter.scheduler.dto.PushResultDTO;
@@ -206,7 +207,7 @@ public class PushController {
         int tableCount = 0;
         
 //        String durl = "jdbc:log4jdbc:cubrid:118.67.133.187:30000:LIFE_CENTER:::?charset=UTF-8";
-        String durl = "jdbc:cubrid:10.175.153.104:30000:LIFE_CENTER:::?altHosts=10.175.153.105:30000&charset=UTF-8";
+        String durl = PropertyUtil.getProperty("spring.datasource.url");
         String user = "dba";
         String passwd = "#zo240s!";