-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/com/nice/petudio/global/config/web/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |