url 패턴, 트랜잭션 pointcut -> 설정으로 분리

master
mjkhan21 6 months ago
parent 53e8138859
commit 93a77162b2

@ -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;
}
}

@ -34,7 +34,6 @@ import cokr.xit.foundation.web.DownloadView;
@EnableWebMvc @EnableWebMvc
@Configuration @Configuration
public class MvcConfig implements WebMvcConfigurer { public class MvcConfig implements WebMvcConfigurer {
protected static String[] URL_PATTERNS = {"/", "/**/*.do"};
@Resource(name = "staticResource") @Resource(name = "staticResource")
private StaticResourceConfig staticResource; private StaticResourceConfig staticResource;
@ -67,7 +66,7 @@ public class MvcConfig implements WebMvcConfigurer {
*/ */
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(accessInitializer()).addPathPatterns(URL_PATTERNS); registry.addInterceptor(accessInitializer()).addPathPatterns(Foundation.urlPatterns());
} }
/**SessionLocaleResolver . /**SessionLocaleResolver .

@ -22,7 +22,6 @@ import cokr.xit.foundation.web.AccessFilter;
*/ */
@Configuration @Configuration
public class ServletConfig { public class ServletConfig {
protected static String[] URL_PATTERNS = {"/", "*.do"};
@Resource(name = "staticResource") @Resource(name = "staticResource")
private StaticResourceConfig staticResource; private StaticResourceConfig staticResource;
@ -33,7 +32,7 @@ public class ServletConfig {
public FilterRegistrationBean<CharacterEncodingFilter> encodingFilter() { public FilterRegistrationBean<CharacterEncodingFilter> encodingFilter() {
FilterRegistrationBean<CharacterEncodingFilter> registration = new FilterRegistrationBean<>(); FilterRegistrationBean<CharacterEncodingFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(new CharacterEncodingFilter("utf-8")); registration.setFilter(new CharacterEncodingFilter("utf-8"));
registration.addUrlPatterns(URL_PATTERNS); registration.addUrlPatterns(Foundation.servletUrls());
registration.setOrder(-102); registration.setOrder(-102);
return registration; return registration;
} }
@ -45,7 +44,7 @@ public class ServletConfig {
public FilterRegistrationBean<AccessFilter> accessFilter() { public FilterRegistrationBean<AccessFilter> accessFilter() {
FilterRegistrationBean<AccessFilter> registration = new FilterRegistrationBean<>(); FilterRegistrationBean<AccessFilter> registration = new FilterRegistrationBean<>();
registration.setFilter(new AccessFilter()); registration.setFilter(new AccessFilter());
registration.addUrlPatterns(URL_PATTERNS); registration.addUrlPatterns(Foundation.servletUrls());
registration.setOrder(-101); registration.setOrder(-101);
return registration; return registration;
} }
@ -81,5 +80,4 @@ public class ServletConfig {
}); });
}; };
} }
} }

@ -66,7 +66,7 @@ public class TransactionConfig {
@Bean @Bean
public Advisor txAdvisor() { 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(); AspectJExpressionPointcut requiredTx = new AspectJExpressionPointcut();
requiredTx.setExpression(expression); requiredTx.setExpression(expression);

@ -0,0 +1,7 @@
{
"servletUrls": ["/", "*.do"], /* 서블릿 url 패턴 */
"urlPatterns": ["/", "/**/*.do"], /* 접근 url 패턴 */
"transactionPointcut": "execution(* cokr.xit..service.bean.*ServiceBean.*(..))" /* 트랜잭션 대상 클래스 및 메소드 */
}

@ -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());
}
}
Loading…
Cancel
Save