티스토리 뷰

Skill/spring

ServiceConfig.java

진열사랑 2025. 1. 13. 10:26

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

'Skill > spring' 카테고리의 다른 글

ServiceInitializer.java  (0) 2025.01.13
ServiceInit.java  (0) 2025.01.13
ServiceAOP.java  (0) 2025.01.13
RedisConfig.java  (0) 2025.01.13
PropertiesCheck.java  (0) 2025.01.13
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함