diff --git a/src/main/java/cokr/xit/foundation/boot/Foundation.java b/src/main/java/cokr/xit/foundation/boot/Foundation.java new file mode 100644 index 0000000..49d6bbd --- /dev/null +++ b/src/main/java/cokr/xit/foundation/boot/Foundation.java @@ -0,0 +1,51 @@ +package cokr.xit.foundation.boot; + +import java.io.InputStream; + +import org.springframework.core.io.ClassPathResource; + +import cokr.xit.foundation.AbstractComponent; +import cokr.xit.foundation.data.JSON; + +public class Foundation extends AbstractComponent { + private static Foundation foundation; + static { + String path = "xit-foundation.conf"; + try (InputStream input = new ClassPathResource(path).getInputStream()) { + foundation = new JSON().parse(input, Foundation.class); + log(Foundation.class).debug(path + " loaded"); + } catch (Exception e) { + foundation = new Foundation(); + log(Foundation.class).debug(path + " not found and default configuration is used"); + } + } + + public static String[] servletUrls() { + return foundation.servletUrls; + } + + public static String[] urlPatterns() { + return foundation.urlPatterns; + } + + public static String transactionPointcut() { + return foundation.transactionPointcut; + } + + private String[] + servletUrls = {"/", "*.do"}, + urlPatterns = {"/", "/**/*.do"}; + private String transactionPointcut = "execution(* cokr.xit..service.bean.*ServiceBean.*(..))"; + + public void setServletUrls(String[] servletUrls) { + this.servletUrls = servletUrls; + } + + public void setUrlPatterns(String[] urlPatterns) { + this.urlPatterns = urlPatterns; + } + + public void setTransactionPointcut(String transactionPointcut) { + this.transactionPointcut = transactionPointcut; + } +} \ No newline at end of file diff --git a/src/main/java/cokr/xit/foundation/boot/MvcConfig.java b/src/main/java/cokr/xit/foundation/boot/MvcConfig.java index fb035e3..b1f88a7 100644 --- a/src/main/java/cokr/xit/foundation/boot/MvcConfig.java +++ b/src/main/java/cokr/xit/foundation/boot/MvcConfig.java @@ -34,7 +34,6 @@ import cokr.xit.foundation.web.DownloadView; @EnableWebMvc @Configuration public class MvcConfig implements WebMvcConfigurer { - protected static String[] URL_PATTERNS = {"/", "/**/*.do"}; @Resource(name = "staticResource") private StaticResourceConfig staticResource; @@ -67,7 +66,7 @@ public class MvcConfig implements WebMvcConfigurer { */ @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(accessInitializer()).addPathPatterns(URL_PATTERNS); + registry.addInterceptor(accessInitializer()).addPathPatterns(Foundation.urlPatterns()); } /**SessionLocaleResolver를 반환한다. diff --git a/src/main/java/cokr/xit/foundation/boot/ServletConfig.java b/src/main/java/cokr/xit/foundation/boot/ServletConfig.java index 5718a14..664f679 100644 --- a/src/main/java/cokr/xit/foundation/boot/ServletConfig.java +++ b/src/main/java/cokr/xit/foundation/boot/ServletConfig.java @@ -22,7 +22,6 @@ import cokr.xit.foundation.web.AccessFilter; */ @Configuration public class ServletConfig { - protected static String[] URL_PATTERNS = {"/", "*.do"}; @Resource(name = "staticResource") private StaticResourceConfig staticResource; @@ -33,7 +32,7 @@ public class ServletConfig { public FilterRegistrationBean encodingFilter() { FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(new CharacterEncodingFilter("utf-8")); - registration.addUrlPatterns(URL_PATTERNS); + registration.addUrlPatterns(Foundation.servletUrls()); registration.setOrder(-102); return registration; } @@ -45,7 +44,7 @@ public class ServletConfig { public FilterRegistrationBean accessFilter() { FilterRegistrationBean registration = new FilterRegistrationBean<>(); registration.setFilter(new AccessFilter()); - registration.addUrlPatterns(URL_PATTERNS); + registration.addUrlPatterns(Foundation.servletUrls()); registration.setOrder(-101); return registration; } @@ -81,5 +80,4 @@ public class ServletConfig { }); }; } - } \ No newline at end of file diff --git a/src/main/java/cokr/xit/foundation/boot/TransactionConfig.java b/src/main/java/cokr/xit/foundation/boot/TransactionConfig.java index 67db7cf..2083267 100644 --- a/src/main/java/cokr/xit/foundation/boot/TransactionConfig.java +++ b/src/main/java/cokr/xit/foundation/boot/TransactionConfig.java @@ -66,7 +66,7 @@ public class TransactionConfig { @Bean public Advisor txAdvisor() { - String expression = "execution(* cokr.xit..service.bean.*ServiceBean.*(..))"; + String expression = Foundation.transactionPointcut(); //"execution(* cokr.xit..service.bean.*ServiceBean.*(..))"; AspectJExpressionPointcut requiredTx = new AspectJExpressionPointcut(); requiredTx.setExpression(expression); diff --git a/src/main/resources/xit-foundation.conf b/src/main/resources/xit-foundation.conf new file mode 100644 index 0000000..658dd37 --- /dev/null +++ b/src/main/resources/xit-foundation.conf @@ -0,0 +1,7 @@ +{ + "servletUrls": ["/", "*.do"], /* 서블릿 url 패턴 */ + + "urlPatterns": ["/", "/**/*.do"], /* 접근 url 패턴 */ + + "transactionPointcut": "execution(* cokr.xit..service.bean.*ServiceBean.*(..))" /* 트랜잭션 대상 클래스 및 메소드 */ +} \ No newline at end of file diff --git a/src/test/java/cokr/xit/foundation/boot/FoundationTest.java b/src/test/java/cokr/xit/foundation/boot/FoundationTest.java new file mode 100644 index 0000000..9d20962 --- /dev/null +++ b/src/test/java/cokr/xit/foundation/boot/FoundationTest.java @@ -0,0 +1,14 @@ +package cokr.xit.foundation.boot; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +public class FoundationTest { + @Test + void conf() { + System.out.println("servletUrls: " + List.of(Foundation.servletUrls())); + System.out.println("urlPatterns: " + List.of(Foundation.urlPatterns())); + System.out.println("transactionPointcut: " + Foundation.transactionPointcut()); + } +} \ No newline at end of file