Loading...
Spring Framework Reference Documentation 7.0.2의 Validation의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
기본적으로 클래스패스에 Bean Validation이 존재하면
(예: Hibernate Validator), LocalValidatorFactoryBean이
컨트롤러 메서드 인수에서 @Valid 및
@Validated와 함께 사용하기 위한 전역 Validator로 등록됩니다.
다음 예에서 보듯이 전역 Validator 인스턴스를 커스터마이즈할 수 있습니다:
1@Configuration 2public class WebConfiguration implements WebMvcConfigurer { 3 4 @Override 5 public Validator getValidator() { 6 Validator validator = new OptionalValidatorFactoryBean(); 7 // ... 8 return validator; 9 } 10}
1@Configuration 2class WebConfiguration : WebMvcConfigurer { 3 4 override fun getValidator(): Validator { 5 val validator = OptionalValidatorFactoryBean() 6 // ... 7 return validator 8 } 9}
1<mvc:annotation-driven validator="globalValidator"/>
또한 다음 예에서 보듯이 Validator implementation을 로컬로 등록할 수도 있습니다:
1@Controller 2public class MyController { 3 4 @InitBinder 5 public void initBinder(WebDataBinder binder) { 6 binder.addValidators(new FooValidator()); 7 } 8}
1@Controller 2class MyController { 3 4 @InitBinder 5 fun initBinder(binder: WebDataBinder) { 6 binder.addValidators(FooValidator()) 7 } 8}
다른 곳에서
LocalValidatorFactoryBean이 주입되어야 한다면, 빈을 생성하고 MVC 설정에 선언된 것과의 충돌을 피하기 위해@Primary로 표시하십시오.
Type Conversion
Interceptors