@Configuration
public class ServiceConfig implements WebMvcConfigurer {
@Value("${static.url}")
private String staticUrl;
@Value("${static.resources.location}")
private String staticResourcesLocation;
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setPrefix("classpath:templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.addDialect(new LayoutDialect());
return templateEngine;
}
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource resourceBundleMessageSource = new ReloadableResourceBundleMessageSource();
resourceBundleMessageSource.setBasename("classpath:locale/Messages");
resourceBundleMessageSource.setDefaultEncoding("UTF-8");
resourceBundleMessageSource.setCacheSeconds(0);
return resourceBundleMessageSource;
}
@Bean
public MessageSourceAccessor messageSourceAccessor(@Qualifier("messageSource") MessageSource messageSource) {
return new MessageSourceAccessor(messageSource);
}
@Bean
public SessionLocaleResolver localeResolver() {
SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
sessionLocaleResolver.setDefaultLocale(new Locale("ko"));
return sessionLocaleResolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(staticUrl + "/**")
.addResourceLocations(staticResourcesLocation)
.setCachePeriod(3600);
}
@Override
public void addInterceptors(InterceptorRegistry objRegistry) {
objRegistry.addInterceptor(loginCheckInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/")
.excludePathPatterns(staticUrl + "/**")
.excludePathPatterns("/favicon.ico")
.excludePathPatterns("/error")
.excludePathPatterns("/login")
.excludePathPatterns("/login/**")
.excludePathPatterns("/administrator/administrator/resetPwd")
.excludePathPatterns("/administrator/administrator/changePwd")
.excludePathPatterns("/common/common/reload");
objRegistry.addInterceptor(baseInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/")
.excludePathPatterns(staticUrl + "/**")
.excludePathPatterns("/favicon.ico")
.excludePathPatterns("/error")
.excludePathPatterns("/login")
.excludePathPatterns("/login/**")
.excludePathPatterns("/administrator/administrator/resetPwd")
.excludePathPatterns("/administrator/administrator/changePwd")
.excludePathPatterns("/common/common/reload");
}
@Bean
public LoginCheckInterceptor loginCheckInterceptor() {
return new LoginCheckInterceptor();
}
@Bean
public BaseInterceptor baseInterceptor() {
return new BaseInterceptor();
}
@Bean
public FilterRegistrationBean multipartFilterRegistrationBean(){
FilterRegistrationBean objRegistrationBean = new FilterRegistrationBean();
objRegistrationBean.setFilter(new MultipartFilter());
objRegistrationBean.addUrlPatterns("/*");
objRegistrationBean.setOrder(0);
return objRegistrationBean;
}
@Bean
public FilterRegistrationBean setXSSFilter() {
FilterRegistrationBean objRegistrationBean = new FilterRegistrationBean();
objRegistrationBean.setFilter(new XSSFilter());
objRegistrationBean.addUrlPatterns("/*");
objRegistrationBean.setOrder(1);
return objRegistrationBean;
}
@Bean
public FilterRegistrationBean setXSSEscapeServletFilter() {
FilterRegistrationBean objRegistrationBean = new FilterRegistrationBean();
objRegistrationBean.setFilter(new XssEscapeServletFilter());
objRegistrationBean.addUrlPatterns("/*");
objRegistrationBean.setOrder(2);
return objRegistrationBean;
}
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> objArgumentResolvers) {
objArgumentResolvers.add(new ArgumentResolver());
}
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
@Bean
public TaskScheduler taskScheduler(){
return new ConcurrentTaskScheduler();
}
@Bean
public MultipartResolver multipartResolver(){
return new CommonsMultipartResolver();
}
@Bean
public HttpSessionListener httpSessionListener(){
return new SessionListener();
}
@Bean
public MethodValidationPostProcessor methodValidationPostProcessor() {
return new MethodValidationPostProcessor();
}
}