package com.nokia.hb.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

/**
 * 校验配置
 */
@Configuration
public class ValidatorConfig
{
    @Bean
    public Validator validator()
    {
        try (ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure()
                .failFast(true).buildValidatorFactory()) {
            return validatorFactory.getValidator();
        }
    }
}
