Skip to content

Commit

Permalink
feat: Interceptor, Resolver 적용 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Jan 18, 2024
1 parent 1241f38 commit a17bfcb
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/main/java/com/nice/petudio/global/config/web/WebMvcConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.nice.petudio.global.config.web;

import com.nice.petudio.global.auth.admin.AdminAuthInterceptor;
import com.nice.petudio.global.auth.auth.AuthInterceptor;
import com.nice.petudio.global.auth.resolver.MemberIdResolver;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.validation.Validator;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@RequiredArgsConstructor
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

private final AdminAuthInterceptor adminInterceptor;
private final AuthInterceptor authInterceptor;
private final MemberIdResolver memberIdResolver;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(adminInterceptor);
registry.addInterceptor(authInterceptor);
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(memberIdResolver);
}

@Bean
public MessageSource validationMessageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("classpath:/messages/validation");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}

@Override
public Validator getValidator() {
LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
bean.setValidationMessageSource(validationMessageSource());
return bean;
}
}

0 comments on commit a17bfcb

Please sign in to comment.