diff --git a/src/main/java/cokr/xit/TestServerApplication.java b/src/main/java/cokr/xit/TestServerApplication.java index 90db6083..e4083a05 100644 --- a/src/main/java/cokr/xit/TestServerApplication.java +++ b/src/main/java/cokr/xit/TestServerApplication.java @@ -1,35 +1,14 @@ package cokr.xit; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import cokr.xit.custom.boot.CommonConfig1; -import cokr.xit.custom.boot.DatasourceConfig1; -import cokr.xit.custom.boot.MvcConfig1; -import cokr.xit.custom.boot.ServletConfig1; -import cokr.xit.custom.boot.ServletConfig2; -import cokr.xit.custom.boot.TransactionConfig1; -import testserver.wsdlserver.lvisserver.WebServiceConfig; +import cokr.xit.custom.boot.XitApplication; -@SpringBootApplication -@ImportAutoConfiguration({ - CommonConfig1.class, - - ServletConfig1.class, - ServletConfig2.class, - - MvcConfig1.class, - DatasourceConfig1.class, - - TransactionConfig1.class, - - WebServiceConfig.class -}) -public class TestServerApplication { +public class TestServerApplication extends XitApplication { public static void main(String[] args) { + SpringApplication.run(TestServerApplication.class, args); } } diff --git a/src/main/java/cokr/xit/custom/boot/CommonConfig1.java b/src/main/java/cokr/xit/custom/boot/CommonConfig.java similarity index 97% rename from src/main/java/cokr/xit/custom/boot/CommonConfig1.java rename to src/main/java/cokr/xit/custom/boot/CommonConfig.java index aa075672..9fa95e9a 100644 --- a/src/main/java/cokr/xit/custom/boot/CommonConfig1.java +++ b/src/main/java/cokr/xit/custom/boot/CommonConfig.java @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Configuration @ComponentScan(basePackages = {"cokr.xit","externalsystem.sinmungo"}) -public class CommonConfig1 { +public class CommonConfig { /**AntPathMatcher를 반환한다. * @return AntPathMatcher */ @@ -61,7 +61,7 @@ public class CommonConfig1 { return new LeaveaTrace(); } - private Yml1 yml = new Yml1("application.yml", "application.yml"); + private Yml yml = new Yml("application.yml", "application.yml"); /**application.yml의 설정 내용을 읽어 MessageSource Bean을 설정하여 반환한다. *
messageSource:
diff --git a/src/main/java/cokr/xit/custom/boot/DatasourceConfig1.java b/src/main/java/cokr/xit/custom/boot/DatasourceConfig.java
similarity index 98%
rename from src/main/java/cokr/xit/custom/boot/DatasourceConfig1.java
rename to src/main/java/cokr/xit/custom/boot/DatasourceConfig.java
index 636140be..cfeece0a 100644
--- a/src/main/java/cokr/xit/custom/boot/DatasourceConfig1.java
+++ b/src/main/java/cokr/xit/custom/boot/DatasourceConfig.java
@@ -14,7 +14,7 @@ import cokr.xit.foundation.Assert;
@Configuration
-public class DatasourceConfig1 {
+public class DatasourceConfig {
private DataSource dataSource;
/**데이터소스 Bean을 반환한다. JDBC 접속은 application.yml 파일에 다음과 같이 설정한다.
* spring:
diff --git a/src/main/java/cokr/xit/custom/boot/MvcConfig1.java b/src/main/java/cokr/xit/custom/boot/MvcConfig.java
similarity index 85%
rename from src/main/java/cokr/xit/custom/boot/MvcConfig1.java
rename to src/main/java/cokr/xit/custom/boot/MvcConfig.java
index 318cb4ab..6411e7c3 100644
--- a/src/main/java/cokr/xit/custom/boot/MvcConfig1.java
+++ b/src/main/java/cokr/xit/custom/boot/MvcConfig.java
@@ -1,13 +1,9 @@
package cokr.xit.custom.boot;
-import javax.annotation.Resource;
-
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
-import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -24,24 +20,16 @@ import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import cokr.xit.foundation.web.AccessInitializer;
-@EnableWebMvc
+
@Configuration
-public class MvcConfig1 implements WebMvcConfigurer {
+public class MvcConfig implements WebMvcConfigurer {
protected static String[] URL_PATTERNS = {"/", "/**/*.do"};
- @Resource(name = "staticResource")
- private StaticResourceConfig1 staticResource;
- /**AccessInitializer를 반환한다.
- * @return AccessInitializer
- */
@Bean
public AccessInitializer accessInitializer() {
return new AccessInitializer();
}
- @Value("${spring.web.resources.static-locations}")
- private String staticLocations;
-
/**정적 파일 자원 접근에 대한 설정을 추가한다.
* - url: /resources/**
* - 위치: /resources/
@@ -49,43 +37,26 @@ public class MvcConfig1 implements WebMvcConfigurer {
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
- staticResource.getMappings().forEach((k, v) ->
- registry
- .addResourceHandler(k)
- .addResourceLocations(v)
- );
+
+ registry.addResourceHandler("/resources/**")
+ .addResourceLocations("/resources/");
+
+ registry.addResourceHandler("/files/**")
+ .addResourceLocations("file:files/");
+
+ registry.addResourceHandler("/webjars/**")
+ .addResourceLocations("classpath:/META-INF/resources/webjars/")
+ .resourceChain(false);
+ registry.setOrder(1);
+
+
}
- /**AccessInitializer를 interceptor로 추가한다.
- */
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(accessInitializer()).addPathPatterns(URL_PATTERNS);
}
- /**BeanNameViewResolver를 반환한다.
- * @return BeanNameViewResolver
- */
- @Bean
- public BeanNameViewResolver beanNameViewResolver() {
- BeanNameViewResolver bean = new BeanNameViewResolver();
- bean.setOrder(0);
- return bean;
- }
-
- /**UrlBasedViewResolver를 반환한다.
- * @return UrlBasedViewResolver
- */
- @Bean
- public UrlBasedViewResolver urlBasedViewResolver() {
- UrlBasedViewResolver bean = new UrlBasedViewResolver();
- bean.setViewClass(JstlView.class);
- bean.setPrefix("/WEB-INF/jsp/");
- bean.setSuffix(".jsp");
- bean.setExposeContextBeansAsAttributes(true);
- bean.setOrder(1);
- return bean;
- }
@Autowired
private ObjectMapper objectMapper;
@@ -135,4 +106,34 @@ public class MvcConfig1 implements WebMvcConfigurer {
public RequestMappingHandlerMapping requestHandlers() {
return new RequestMappingHandlerMapping();
}
+
+ /**BeanNameViewResolver를 반환한다.
+ * @return BeanNameViewResolver
+ */
+ @Bean
+ public BeanNameViewResolver beanNameViewResolver() {
+ BeanNameViewResolver bean = new BeanNameViewResolver();
+ bean.setOrder(0);
+ return bean;
+ }
+
+ /**UrlBasedViewResolver를 반환한다.
+ * @return UrlBasedViewResolver
+ */
+ @Bean
+ public UrlBasedViewResolver urlBasedViewResolver() {
+ UrlBasedViewResolver bean = new UrlBasedViewResolver();
+ bean.setViewClass(JstlView.class);
+ bean.setPrefix("/WEB-INF/jsp/");
+ bean.setSuffix(".jsp");
+ bean.setExposeContextBeansAsAttributes(true);
+ bean.setOrder(1);
+ return bean;
+ }
+
+
+
+
+
+
}
diff --git a/src/main/java/cokr/xit/custom/boot/ServletConfig1.java b/src/main/java/cokr/xit/custom/boot/ServletConfig.java
similarity index 86%
rename from src/main/java/cokr/xit/custom/boot/ServletConfig1.java
rename to src/main/java/cokr/xit/custom/boot/ServletConfig.java
index c63f5ace..2407199a 100644
--- a/src/main/java/cokr/xit/custom/boot/ServletConfig1.java
+++ b/src/main/java/cokr/xit/custom/boot/ServletConfig.java
@@ -1,14 +1,11 @@
package cokr.xit.custom.boot;
-import static org.assertj.core.api.Assertions.entry;
-
import java.util.Map;
-import javax.annotation.Resource;
-
import org.apache.catalina.Context;
import org.apache.catalina.servlets.DefaultServlet;
import org.apache.catalina.webresources.ExtractingRoot;
+import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
@@ -20,11 +17,37 @@ import org.springframework.web.filter.CharacterEncodingFilter;
import cokr.xit.foundation.web.AccessFilter;
@Configuration
-public class ServletConfig1 {
+public class ServletConfig {
protected static String[] URL_PATTERNS = {"/", "*.do"};
- @Resource(name = "staticResource")
- private StaticResourceConfig1 staticResource;
+ /**DefaultServlet를 등록한다.
+ * @return ServletRegistrationBean
+ */
+ @Bean
+ public ServletRegistrationBean defaultServlet() {
+
+ ServletRegistrationBean bean = new ServletRegistrationBean<>(
+ new DefaultServlet(),
+ "/resources/*","/webjars/*"
+ );
+ bean.setLoadOnStartup(1);
+ bean.setInitParameters(Map.of(
+ "debug", "0",
+ "listings", "false"
+ ));
+ return bean;
+ }
+
+ @Bean
+ public ServletRegistrationBean cxfServlet() {
+ ServletRegistrationBean bean = new ServletRegistrationBean<>(
+ new CXFServlet(),
+ "/lvis/services/*"
+ );
+ bean.setLoadOnStartup(2);
+ return bean;
+ }
+
/**CharacterEncodingFilter를 등록한다.
* @return FilterRegistrationBean
@@ -50,28 +73,6 @@ public class ServletConfig1 {
return registration;
}
- /**DefaultServlet를 등록한다.
- * @return ServletRegistrationBean
- */
- @Bean
- public ServletRegistrationBean defaultServlet() {
- String[] urls = staticResource.getURLs(entry -> !entry.getValue().startsWith("file:"));
- for (int i = 0; i bean = new ServletRegistrationBean<>(
- new DefaultServlet(),
- urls
- );
- bean.setLoadOnStartup(1);
- bean.setInitParameters(Map.of(
- "debug", "0",
- "listings", "false"
- ));
-
- return bean;
- }
-
@Bean
public WebServerFactoryCustomizer servletContainerCustomizer() {
return (TomcatServletWebServerFactory container) -> {
diff --git a/src/main/java/cokr/xit/custom/boot/ServletConfig2.java b/src/main/java/cokr/xit/custom/boot/ServletConfig2.java
deleted file mode 100644
index 97bb0146..00000000
--- a/src/main/java/cokr/xit/custom/boot/ServletConfig2.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package cokr.xit.custom.boot;
-
-import org.apache.cxf.transport.servlet.CXFServlet;
-import org.springframework.boot.web.servlet.ServletRegistrationBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class ServletConfig2 {
-
- @Bean
- public ServletRegistrationBean cxfServlet() {
- return new ServletRegistrationBean<>(new CXFServlet(), "/lvis/services/*");
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/cokr/xit/custom/boot/StandAloneApplication1.java b/src/main/java/cokr/xit/custom/boot/StandAloneApplication1.java
deleted file mode 100644
index 7129a52b..00000000
--- a/src/main/java/cokr/xit/custom/boot/StandAloneApplication1.java
+++ /dev/null
@@ -1,28 +0,0 @@
-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;
-
-@SpringBootApplication(exclude = {
- WebMvcAutoConfiguration.class
-})
-@ImportAutoConfiguration({
- CommonConfig1.class,
- DatasourceConfig1.class,
- TransactionConfig1.class,
-})
-public class StandAloneApplication1 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);
- }
-
-}
diff --git a/src/main/java/cokr/xit/custom/boot/StaticResourceConfig1.java b/src/main/java/cokr/xit/custom/boot/StaticResourceConfig1.java
deleted file mode 100644
index f9db98be..00000000
--- a/src/main/java/cokr/xit/custom/boot/StaticResourceConfig1.java
+++ /dev/null
@@ -1,56 +0,0 @@
-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 StaticResourceConfig1 {
-
- @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()]);
- }
-}
diff --git a/src/main/java/cokr/xit/custom/boot/TransactionConfig1.java b/src/main/java/cokr/xit/custom/boot/TransactionConfig.java
similarity index 98%
rename from src/main/java/cokr/xit/custom/boot/TransactionConfig1.java
rename to src/main/java/cokr/xit/custom/boot/TransactionConfig.java
index b39e45c2..27b2355a 100644
--- a/src/main/java/cokr/xit/custom/boot/TransactionConfig1.java
+++ b/src/main/java/cokr/xit/custom/boot/TransactionConfig.java
@@ -25,7 +25,7 @@ import org.springframework.transaction.interceptor.TransactionInterceptor;
@Aspect
@EnableTransactionManagement
@EnableAspectJAutoProxy(proxyTargetClass = true)
-public class TransactionConfig1 {
+public class TransactionConfig {
@Resource(name = "dataSource")
private DataSource dataSource;
diff --git a/src/main/java/cokr/xit/custom/boot/XitApplication.java b/src/main/java/cokr/xit/custom/boot/XitApplication.java
new file mode 100644
index 00000000..02a3ddf2
--- /dev/null
+++ b/src/main/java/cokr/xit/custom/boot/XitApplication.java
@@ -0,0 +1,17 @@
+package cokr.xit.custom.boot;
+
+import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import testserver.wsdlserver.lvisserver.WebServiceConfig;
+
+@SpringBootApplication
+@ImportAutoConfiguration({
+ CommonConfig.class,
+ ServletConfig.class,
+ MvcConfig.class,
+ DatasourceConfig.class,
+ TransactionConfig.class,
+ WebServiceConfig.class
+})
+public class XitApplication {}
diff --git a/src/main/java/cokr/xit/custom/boot/Yml1.java b/src/main/java/cokr/xit/custom/boot/Yml.java
similarity index 97%
rename from src/main/java/cokr/xit/custom/boot/Yml1.java
rename to src/main/java/cokr/xit/custom/boot/Yml.java
index 923d373b..f72b09bf 100644
--- a/src/main/java/cokr/xit/custom/boot/Yml1.java
+++ b/src/main/java/cokr/xit/custom/boot/Yml.java
@@ -12,14 +12,14 @@ import org.springframework.core.io.ClassPathResource;
import cokr.xit.foundation.Assert;
-public class Yml1 {
+public class Yml {
private Map source;
/**새 Yml을 생성한다.
* @param rootName 프로퍼티 소스의 루트 이름
* @param path 클래스패스에서 yml 파일의 경로
*/
- public Yml1(String rootName, String path) {
+ public Yml(String rootName, String path) {
load(rootName, path);
}
@@ -28,7 +28,7 @@ public class Yml1 {
* @param path 클래스패스에서 yml 파일의 경로
* @return 현재 Yml
*/
- public Yml1 load(String rootName, String path) {
+ public Yml load(String rootName, String path) {
source = null;
try {
List> sources = new YamlPropertySourceLoader()