From 82320c60b26f079ea1979e506380ea7bac57039f Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Tue, 10 Oct 2023 09:19:48 +0900 Subject: [PATCH] no message --- pom.xml | 55 ++++++-- .../{base => custom}/boot/CommonConfig2.java | 8 +- .../boot/DatasourceConfig2.java | 2 +- .../xit/{base => custom}/boot/MvcConfig4.java | 7 +- .../{base => custom}/boot/ServletConfig2.java | 6 +- .../custom/boot/StandAloneApplication2.java | 37 +++++ .../custom/boot/StaticResourceConfig2.java | 55 ++++++++ .../boot/TransactionConfig2.java | 2 +- .../boot/WebServiceConfig.java | 2 +- .../boot/XitBaseApplication2.java | 2 +- src/main/java/cokr/xit/custom/boot/Yml2.java | 130 ++++++++++++++++++ src/main/java/testserver/TsApplication.java | 2 +- src/main/resources/application.yml | 3 - 13 files changed, 276 insertions(+), 35 deletions(-) rename src/main/java/cokr/xit/{base => custom}/boot/CommonConfig2.java (95%) rename src/main/java/cokr/xit/{base => custom}/boot/DatasourceConfig2.java (99%) rename src/main/java/cokr/xit/{base => custom}/boot/MvcConfig4.java (95%) rename src/main/java/cokr/xit/{base => custom}/boot/ServletConfig2.java (95%) create mode 100644 src/main/java/cokr/xit/custom/boot/StandAloneApplication2.java create mode 100644 src/main/java/cokr/xit/custom/boot/StaticResourceConfig2.java rename src/main/java/cokr/xit/{base => custom}/boot/TransactionConfig2.java (98%) rename src/main/java/cokr/xit/{base => custom}/boot/WebServiceConfig.java (97%) rename src/main/java/cokr/xit/{base => custom}/boot/XitBaseApplication2.java (94%) create mode 100644 src/main/java/cokr/xit/custom/boot/Yml2.java diff --git a/pom.xml b/pom.xml index d760ab36..856bb154 100644 --- a/pom.xml +++ b/pom.xml @@ -36,22 +36,26 @@ 23.04.01-SNAPSHOT - cokr.xit.base - xit-security + cokr.xit.base + xit-security - cokr.xit.boot - xit-foundation-starter + cokr.xit.base + xit-foundation 23.04.01-SNAPSHOT - - cokr.xit.base - xit-security + + javax.servlet + javax.servlet-api + + + cokr.xit.base + xit-security - + @@ -66,19 +70,42 @@ 3.3.6 + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-configuration-processor + + + org.springframework.boot + spring-boot-devtools + + + org.springframework.boot + spring-boot-starter-test + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.3.1 + + + org.apache.tomcat.embed + tomcat-embed-jasper + org.hibernate hibernate-validator - 6.1.5.Final + 5.3.6.Final - javax - javaee-api - 8.0 - provided + org.projectlombok + lombok - + diff --git a/src/main/java/cokr/xit/base/boot/CommonConfig2.java b/src/main/java/cokr/xit/custom/boot/CommonConfig2.java similarity index 95% rename from src/main/java/cokr/xit/base/boot/CommonConfig2.java rename to src/main/java/cokr/xit/custom/boot/CommonConfig2.java index 215f6214..032c208c 100644 --- a/src/main/java/cokr/xit/base/boot/CommonConfig2.java +++ b/src/main/java/cokr/xit/custom/boot/CommonConfig2.java @@ -1,4 +1,4 @@ -package cokr.xit.base.boot; +package cokr.xit.custom.boot; import java.text.SimpleDateFormat; import java.util.List; @@ -19,8 +19,6 @@ import org.springframework.web.servlet.i18n.SessionLocaleResolver; import com.fasterxml.jackson.core.JsonParser.Feature; import com.fasterxml.jackson.databind.ObjectMapper; -import cokr.xit.foundation.boot.Yml; - /**전자정부 프레임웤과 xit foundation을 사용하는 애플리케이션의 공통 Bean들을 설정한다. * @author mjkhan */ @@ -49,7 +47,7 @@ public class CommonConfig2 { /**SessionLocaleResolver를 반환한다. * @return SessionLocaleResolver */ - @Bean(name="localeResolver2") + @Bean(name="localeResolver") public SessionLocaleResolver localeResolver() { SessionLocaleResolver bean = new SessionLocaleResolver(); bean.setDefaultLocale(Locale.getDefault()); @@ -64,7 +62,7 @@ public class CommonConfig2 { return new LeaveaTrace(); } - private Yml yml = new Yml("application.yml", "application.yml"); + private Yml2 yml = new Yml2("application.yml", "application.yml"); /**application.yml의 설정 내용을 읽어 MessageSource Bean을 설정하여 반환한다. *
 messageSource:
diff --git a/src/main/java/cokr/xit/base/boot/DatasourceConfig2.java b/src/main/java/cokr/xit/custom/boot/DatasourceConfig2.java
similarity index 99%
rename from src/main/java/cokr/xit/base/boot/DatasourceConfig2.java
rename to src/main/java/cokr/xit/custom/boot/DatasourceConfig2.java
index 1e2f0d9e..af7cead0 100644
--- a/src/main/java/cokr/xit/base/boot/DatasourceConfig2.java
+++ b/src/main/java/cokr/xit/custom/boot/DatasourceConfig2.java
@@ -1,4 +1,4 @@
-package cokr.xit.base.boot;
+package cokr.xit.custom.boot;
 
 import javax.sql.DataSource;
 
diff --git a/src/main/java/cokr/xit/base/boot/MvcConfig4.java b/src/main/java/cokr/xit/custom/boot/MvcConfig4.java
similarity index 95%
rename from src/main/java/cokr/xit/base/boot/MvcConfig4.java
rename to src/main/java/cokr/xit/custom/boot/MvcConfig4.java
index efb19561..bb0b9e12 100644
--- a/src/main/java/cokr/xit/base/boot/MvcConfig4.java
+++ b/src/main/java/cokr/xit/custom/boot/MvcConfig4.java
@@ -1,4 +1,4 @@
-package cokr.xit.base.boot;
+package cokr.xit.custom.boot;
 
 import javax.annotation.Resource;
 
@@ -15,19 +15,18 @@ import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 
-import cokr.xit.foundation.boot.StaticResourceConfig;
 import cokr.xit.foundation.web.AccessInitializer;
 
 @Configuration
 public class MvcConfig4 implements WebMvcConfigurer {
 	protected static String[] URL_PATTERNS = {"/lvis/**/*"};
 	@Resource(name = "staticResource")
-	private StaticResourceConfig staticResource;
+	private StaticResourceConfig2 staticResource;
 
 	/**AccessInitializer를 반환한다.
 	 * @return AccessInitializer
 	 */
-	@Bean
+	@Bean(name="accessInitializer2")
 	public AccessInitializer accessInitializer() {
 		return new AccessInitializer();
 	}
diff --git a/src/main/java/cokr/xit/base/boot/ServletConfig2.java b/src/main/java/cokr/xit/custom/boot/ServletConfig2.java
similarity index 95%
rename from src/main/java/cokr/xit/base/boot/ServletConfig2.java
rename to src/main/java/cokr/xit/custom/boot/ServletConfig2.java
index 55e46fe5..6da023c1 100644
--- a/src/main/java/cokr/xit/base/boot/ServletConfig2.java
+++ b/src/main/java/cokr/xit/custom/boot/ServletConfig2.java
@@ -1,4 +1,4 @@
-package cokr.xit.base.boot;
+package cokr.xit.custom.boot;
 
 import javax.annotation.Resource;
 
@@ -13,13 +13,11 @@ import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.filter.CharacterEncodingFilter;
 
-import cokr.xit.foundation.boot.StaticResourceConfig;
-
 @Configuration
 public class ServletConfig2 {
 	protected static String[] URL_PATTERNS = {"/","*.do"};
 	@Resource(name = "staticResource")
-	private StaticResourceConfig staticResource;
+	private StaticResourceConfig2 staticResource;
 
 	/**CharacterEncodingFilter를 등록한다.
 	 * @return FilterRegistrationBean
diff --git a/src/main/java/cokr/xit/custom/boot/StandAloneApplication2.java b/src/main/java/cokr/xit/custom/boot/StandAloneApplication2.java
new file mode 100644
index 00000000..eeb1ae29
--- /dev/null
+++ b/src/main/java/cokr/xit/custom/boot/StandAloneApplication2.java
@@ -0,0 +1,37 @@
+package cokr.xit.custom.boot;
+
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
+import org.springframework.test.context.ContextConfiguration;
+
+/**Spring Boot에서 xit-foundation.jar를 사용하는 stand-alone 애플리케이션의 베이스 클래스
+ * 

설정 파일을 추가하여 사용하는 경우 설정 파일은 + *

  • 클래스패스의 spring 폴더 아래에 있어야 하고
  • + *
  • 이름은 'context-'로 시작하는 xml이어야 한다
  • + *
  • 즉 classpath*:spring/context-*.xml 경로에 해당해야 한다.
  • + *
+ * @author mjkhan + */ +@SpringBootApplication(exclude = { + WebMvcAutoConfiguration.class +}) +@ImportAutoConfiguration({ + CommonConfig2.class, + DatasourceConfig2.class, + TransactionConfig2.class, +}) +@ContextConfiguration("classpath:spring/context-*.xml") +public class StandAloneApplication2 implements CommandLineRunner { + @Override + public void run(String... args) throws Exception {} + + protected static void start(Class klass, String... args) { + SpringApplication app = new SpringApplication(klass); + app.setWebApplicationType(WebApplicationType.NONE); + app.run(args); + } +} \ No newline at end of file diff --git a/src/main/java/cokr/xit/custom/boot/StaticResourceConfig2.java b/src/main/java/cokr/xit/custom/boot/StaticResourceConfig2.java new file mode 100644 index 00000000..3c039304 --- /dev/null +++ b/src/main/java/cokr/xit/custom/boot/StaticResourceConfig2.java @@ -0,0 +1,55 @@ +package cokr.xit.custom.boot; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import cokr.xit.foundation.Assert; +import cokr.xit.foundation.data.StringMap; + +@Configuration("staticResource") +public class StaticResourceConfig2 { + @Value("${spring.mvc.static-path-pattern}") + private String staticURLs; + @Value("${spring.web.resources.static-locations}") + private String staticLocations; + + public Map getMappings() { + if (Assert.isEmpty(staticURLs) && Assert.isEmpty(staticLocations)) + return Collections.emptyMap(); + + List + urls = Arrays.asList(staticURLs.split(",")), + locations = Arrays.asList(staticLocations.split(",")); + if (urls.size() != locations.size()) + throw new RuntimeException("URLs and locations do not match in size for static resources"); + + StringMap resMap = new StringMap<>(); + for (int i = 0; i < urls.size(); ++i) { + String url = urls.get(i), + location = locations.get(i); + resMap.put(url.trim(), location.trim()); + } + + return resMap; + } + + public String[] getURLs(Predicate> filter) { + Predicate> test = filter != null ? filter : entry -> true; + List urls = getMappings().entrySet().stream() + .filter(test) + .map(entry -> entry.getKey()) + .toList(); + return urls.toArray(new String[urls.size()]); + } + + public String[] getLocations() { + List locations = getMappings().values().stream().toList(); + return locations.toArray(new String[locations.size()]); + } +} \ No newline at end of file diff --git a/src/main/java/cokr/xit/base/boot/TransactionConfig2.java b/src/main/java/cokr/xit/custom/boot/TransactionConfig2.java similarity index 98% rename from src/main/java/cokr/xit/base/boot/TransactionConfig2.java rename to src/main/java/cokr/xit/custom/boot/TransactionConfig2.java index de48f4d2..f0092b60 100644 --- a/src/main/java/cokr/xit/base/boot/TransactionConfig2.java +++ b/src/main/java/cokr/xit/custom/boot/TransactionConfig2.java @@ -1,4 +1,4 @@ -package cokr.xit.base.boot; +package cokr.xit.custom.boot; import java.util.List; import java.util.Map; diff --git a/src/main/java/cokr/xit/base/boot/WebServiceConfig.java b/src/main/java/cokr/xit/custom/boot/WebServiceConfig.java similarity index 97% rename from src/main/java/cokr/xit/base/boot/WebServiceConfig.java rename to src/main/java/cokr/xit/custom/boot/WebServiceConfig.java index 2778ceb7..738db4ab 100644 --- a/src/main/java/cokr/xit/base/boot/WebServiceConfig.java +++ b/src/main/java/cokr/xit/custom/boot/WebServiceConfig.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package cokr.xit.base.boot; +package cokr.xit.custom.boot; import javax.xml.ws.Endpoint; diff --git a/src/main/java/cokr/xit/base/boot/XitBaseApplication2.java b/src/main/java/cokr/xit/custom/boot/XitBaseApplication2.java similarity index 94% rename from src/main/java/cokr/xit/base/boot/XitBaseApplication2.java rename to src/main/java/cokr/xit/custom/boot/XitBaseApplication2.java index c6de43e2..e959274c 100644 --- a/src/main/java/cokr/xit/base/boot/XitBaseApplication2.java +++ b/src/main/java/cokr/xit/custom/boot/XitBaseApplication2.java @@ -1,4 +1,4 @@ -package cokr.xit.base.boot; +package cokr.xit.custom.boot; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/cokr/xit/custom/boot/Yml2.java b/src/main/java/cokr/xit/custom/boot/Yml2.java new file mode 100644 index 00000000..96f4a438 --- /dev/null +++ b/src/main/java/cokr/xit/custom/boot/Yml2.java @@ -0,0 +1,130 @@ +package cokr.xit.custom.boot; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.springframework.boot.env.YamlPropertySourceLoader; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.ClassPathResource; + +import cokr.xit.foundation.Assert; + +/**yml 파일 내용을 프로퍼티 형식으로 읽기를 지원하는 유틸리티. + *

+ * @author mjkhan + */ +public class Yml2 { + private Map source; + + /**새 Yml을 생성한다. + * @param rootName 프로퍼티 소스의 루트 이름 + * @param path 클래스패스에서 yml 파일의 경로 + */ + public Yml2(String rootName, String path) { + load(rootName, path); + } + + /**지정하는 yml 파일의 프로퍼티들을 읽어들인다. + * @param rootName 프로퍼티 소스의 루트 이름 + * @param path 클래스패스에서 yml 파일의 경로 + * @return 현재 Yml + */ + public Yml2 load(String rootName, String path) { + source = null; + try { + List> sources = new YamlPropertySourceLoader() + .load(rootName, new ClassPathResource(path)); + if (!sources.isEmpty()) + source = (Map)sources.get(0).getSource(); + return this; + } catch (Exception e) { + throw Assert.runtimeException(e); + } + } + + /**지정하는 프로퍼티(아래 참고)의 값을 반환한다. + * @param key 키. 프로퍼티 이름 + *

 spring:
+	 *   application:
+	 *     name: my-application
+	 * 
+ * @return 지정하는 키의 프로퍼티 값 + */ + public String getValue(String key) { + if (source == null) return ""; + + Object obj = source.get(key); + return obj != null ? obj.toString() : ""; + } + + /**지정하는 문자열로 시작하는 프로퍼티(아래 참고) 값들을 반환한다. + *
 list:
+	 *   - item-0
+	 *   - item-2
+	 *   - item-3
+ * @param prefix 프로퍼티 접두어 + * @return 지정하는 문자열로 시작하는 프로퍼티 값 + */ + public List getValues(String prefix) { + if (source == null) return Collections.emptyList(); + + return getPrefixed(prefix).stream() + .map(entry -> entry.getValue().toString()) + .collect(Collectors.toList()); + } + + private List> getPrefixed(String prefix) { + return source.entrySet().stream() + .filter(entry -> entry.getKey().startsWith(prefix)) + .collect(Collectors.toList()); + } + + /**지정하는 문자열로 시작하는 프로퍼티(아래 참고) 값들을 Map으로 반환한다. + *
 parent:
+	 *   - property-0: value-0
+	 *   - property-1: value-1
+	 *   - property-2: value-2
+ * @param prefix 프로퍼티 접두어 + * @return 지정하는 문자열로 시작하는 프로퍼티로 된 Map + */ + public Map getMap(String prefix) { + if (source == null) return Collections.emptyMap(); + + LinkedHashMap map = new LinkedHashMap<>(); + getPrefixed(prefix).stream().forEach(entry -> putTo(map, entry)); + + return map; + } + + private void putTo(LinkedHashMap map, Map.Entry entry) { + String key = entry.getKey(); + key = key.substring(key.lastIndexOf(".") + 1); + String val = entry.getValue().toString(); + map.put(key, val); + } + + /**지정하는 문자열로 시작하는 프로퍼티들(아래 참고)을 Map 목록으로 반환한다. + *
 parent:
+	 *   - property-0: value-0.0
+	 *     property-1: value-0.1
+	 *   - property-0: value-1.0
+	 *     property-1: value-1.1
+ * @param prefix 프로퍼티 접두어 + * @return 지정하는 문자열로 시작하는 프로퍼티들의 Map 목록 + */ + public List> getMaps(String prefix) { + if (source == null) return Collections.emptyList(); + + return getPrefixed(prefix).stream() + .map(entry -> { + String str = entry.getKey(); + return str.substring(0, str.lastIndexOf(".")); + }) + .collect(Collectors.toSet()).stream() + .map(this::getMap) + .collect(Collectors.toList()); + } +} \ No newline at end of file diff --git a/src/main/java/testserver/TsApplication.java b/src/main/java/testserver/TsApplication.java index 5089e86d..21a14fa0 100644 --- a/src/main/java/testserver/TsApplication.java +++ b/src/main/java/testserver/TsApplication.java @@ -3,7 +3,7 @@ package testserver; import org.springframework.boot.SpringApplication; import org.springframework.context.annotation.ImportResource; -import cokr.xit.base.boot.XitBaseApplication2; +import cokr.xit.custom.boot.XitBaseApplication2; @ImportResource("classpath:spring/context-*.xml") public class TsApplication extends XitBaseApplication2 { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 14129199..c46c1838 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,13 +6,11 @@ server: spring: application: name: dummy-external-system - main: allow-bean-definition-overriding: true sql: init: platform: mariadb - datasource: hikari: driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy @@ -27,7 +25,6 @@ spring: username: fimsweb password: fimsweb!@ auto-commit: false - mvc: static-path-pattern: /resources/**,/files/** web: