소스 정리

main
이범준 5 months ago
parent 30c652dcbf
commit 67bca345ae

@ -1,35 +1,14 @@
package cokr.xit; package cokr.xit;
import org.springframework.boot.SpringApplication; 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.XitApplication;
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;
@SpringBootApplication
@ImportAutoConfiguration({
CommonConfig1.class, public class TestServerApplication extends XitApplication {
ServletConfig1.class,
ServletConfig2.class,
MvcConfig1.class,
DatasourceConfig1.class,
TransactionConfig1.class,
WebServiceConfig.class
})
public class TestServerApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(TestServerApplication.class, args); SpringApplication.run(TestServerApplication.class, args);
} }
} }

@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration @Configuration
@ComponentScan(basePackages = {"cokr.xit","externalsystem.sinmungo"}) @ComponentScan(basePackages = {"cokr.xit","externalsystem.sinmungo"})
public class CommonConfig1 { public class CommonConfig {
/**AntPathMatcher . /**AntPathMatcher .
* @return AntPathMatcher * @return AntPathMatcher
*/ */
@ -61,7 +61,7 @@ public class CommonConfig1 {
return new LeaveaTrace(); 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 . /**application.yml MessageSource Bean .
* <pre><code> messageSource: * <pre><code> messageSource:

@ -14,7 +14,7 @@ import cokr.xit.foundation.Assert;
@Configuration @Configuration
public class DatasourceConfig1 { public class DatasourceConfig {
private DataSource dataSource; private DataSource dataSource;
/** Bean . JDBC application.yml . /** Bean . JDBC application.yml .
* <pre><code> spring: * <pre><code> spring:

@ -1,13 +1,9 @@
package cokr.xit.custom.boot; package cokr.xit.custom.boot;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver; 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.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 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; import cokr.xit.foundation.web.AccessInitializer;
@EnableWebMvc
@Configuration @Configuration
public class MvcConfig1 implements WebMvcConfigurer { public class MvcConfig implements WebMvcConfigurer {
protected static String[] URL_PATTERNS = {"/", "/**/*.do"}; protected static String[] URL_PATTERNS = {"/", "/**/*.do"};
@Resource(name = "staticResource")
private StaticResourceConfig1 staticResource;
/**AccessInitializer .
* @return AccessInitializer
*/
@Bean @Bean
public AccessInitializer accessInitializer() { public AccessInitializer accessInitializer() {
return new AccessInitializer(); return new AccessInitializer();
} }
@Value("${spring.web.resources.static-locations}")
private String staticLocations;
/** . /** .
* <ul><li>url: /resources/** </li> * <ul><li>url: /resources/** </li>
* <li>: /resources/</li> * <li>: /resources/</li>
@ -49,43 +37,26 @@ public class MvcConfig1 implements WebMvcConfigurer {
*/ */
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
staticResource.getMappings().forEach((k, v) ->
registry registry.addResourceHandler("/resources/**")
.addResourceHandler(k) .addResourceLocations("/resources/");
.addResourceLocations(v)
); registry.addResourceHandler("/files/**")
.addResourceLocations("file:files/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/")
.resourceChain(false);
registry.setOrder(1);
} }
/**AccessInitializer interceptor .
*/
@Override @Override
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(accessInitializer()).addPathPatterns(URL_PATTERNS); 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 @Autowired
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@ -135,4 +106,34 @@ public class MvcConfig1 implements WebMvcConfigurer {
public RequestMappingHandlerMapping requestHandlers() { public RequestMappingHandlerMapping requestHandlers() {
return new RequestMappingHandlerMapping(); 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;
}
} }

@ -1,14 +1,11 @@
package cokr.xit.custom.boot; package cokr.xit.custom.boot;
import static org.assertj.core.api.Assertions.entry;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource;
import org.apache.catalina.Context; import org.apache.catalina.Context;
import org.apache.catalina.servlets.DefaultServlet; import org.apache.catalina.servlets.DefaultServlet;
import org.apache.catalina.webresources.ExtractingRoot; 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.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
@ -20,11 +17,37 @@ import org.springframework.web.filter.CharacterEncodingFilter;
import cokr.xit.foundation.web.AccessFilter; import cokr.xit.foundation.web.AccessFilter;
@Configuration @Configuration
public class ServletConfig1 { public class ServletConfig {
protected static String[] URL_PATTERNS = {"/", "*.do"}; protected static String[] URL_PATTERNS = {"/", "*.do"};
@Resource(name = "staticResource") /**DefaultServlet .
private StaticResourceConfig1 staticResource; * @return ServletRegistrationBean
*/
@Bean
public ServletRegistrationBean<DefaultServlet> defaultServlet() {
ServletRegistrationBean<DefaultServlet> bean = new ServletRegistrationBean<>(
new DefaultServlet(),
"/resources/*","/webjars/*"
);
bean.setLoadOnStartup(1);
bean.setInitParameters(Map.of(
"debug", "0",
"listings", "false"
));
return bean;
}
@Bean
public ServletRegistrationBean<CXFServlet> cxfServlet() {
ServletRegistrationBean<CXFServlet> bean = new ServletRegistrationBean<>(
new CXFServlet(),
"/lvis/services/*"
);
bean.setLoadOnStartup(2);
return bean;
}
/**CharacterEncodingFilter . /**CharacterEncodingFilter .
* @return FilterRegistrationBean * @return FilterRegistrationBean
@ -50,28 +73,6 @@ public class ServletConfig1 {
return registration; return registration;
} }
/**DefaultServlet .
* @return ServletRegistrationBean
*/
@Bean
public ServletRegistrationBean<DefaultServlet> defaultServlet() {
String[] urls = staticResource.getURLs(entry -> !entry.getValue().startsWith("file:"));
for (int i = 0; i <urls.length; ++i)
urls[i] = urls[i].replace("/**", "/*");
ServletRegistrationBean<DefaultServlet> bean = new ServletRegistrationBean<>(
new DefaultServlet(),
urls
);
bean.setLoadOnStartup(1);
bean.setInitParameters(Map.of(
"debug", "0",
"listings", "false"
));
return bean;
}
@Bean @Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainerCustomizer() { public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainerCustomizer() {
return (TomcatServletWebServerFactory container) -> { return (TomcatServletWebServerFactory container) -> {

@ -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> cxfServlet() {
return new ServletRegistrationBean<>(new CXFServlet(), "/lvis/services/*");
}
}

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

@ -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<String, String> getMappings() {
if (Assert.isEmpty(staticURLs) && Assert.isEmpty(staticLocations))
return Collections.emptyMap();
List<String>
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<String> 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<Map.Entry<String, String>> filter) {
Predicate<Map.Entry<String, String>> test = filter != null ? filter : entry -> true;
List<String> urls = getMappings().entrySet().stream()
.filter(test)
.map(entry -> entry.getKey())
.toList();
return urls.toArray(new String[urls.size()]);
}
public String[] getLocations() {
List<String> locations = getMappings().values().stream().toList();
return locations.toArray(new String[locations.size()]);
}
}

@ -25,7 +25,7 @@ import org.springframework.transaction.interceptor.TransactionInterceptor;
@Aspect @Aspect
@EnableTransactionManagement @EnableTransactionManagement
@EnableAspectJAutoProxy(proxyTargetClass = true) @EnableAspectJAutoProxy(proxyTargetClass = true)
public class TransactionConfig1 { public class TransactionConfig {
@Resource(name = "dataSource") @Resource(name = "dataSource")
private DataSource dataSource; private DataSource dataSource;

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

@ -12,14 +12,14 @@ import org.springframework.core.io.ClassPathResource;
import cokr.xit.foundation.Assert; import cokr.xit.foundation.Assert;
public class Yml1 { public class Yml {
private Map<String, ?> source; private Map<String, ?> source;
/** Yml . /** Yml .
* @param rootName * @param rootName
* @param path yml * @param path yml
*/ */
public Yml1(String rootName, String path) { public Yml(String rootName, String path) {
load(rootName, path); load(rootName, path);
} }
@ -28,7 +28,7 @@ public class Yml1 {
* @param path yml * @param path yml
* @return Yml * @return Yml
*/ */
public Yml1 load(String rootName, String path) { public Yml load(String rootName, String path) {
source = null; source = null;
try { try {
List<PropertySource<?>> sources = new YamlPropertySourceLoader() List<PropertySource<?>> sources = new YamlPropertySourceLoader()
Loading…
Cancel
Save