hibernate-validator

Spring Validation vs Hibernate Validation

烈酒焚心 提交于 2019-12-04 10:43:33
问题 I am confused between the two now. I know Hibernate Validator 6 is the reference implementation for Bean Validation 2.0 specs. It supports Grouping, Internationalization of error messages, Custom Method Validations etc. Question is does Spring 5 support these features or am I only left with Hibernate Validator 6? Why should I used Hibernate Validator along with my Spring Boot project instead of the provided Spring Validation? My company needs a justification to use any third party library.

Empty validatedBy in @Constraint

十年热恋 提交于 2019-12-04 10:27:44
问题 I noticed that all built-in constraints have an empty value for the validatedBy parameter in @Constraint . i.e. @Constraint(validatedBy = {}) First, why are they allowed to have an empty value for validatedBy ? I thought you can leave it blank only for constraint composition that does not need addtional validation? Also, note that the Hibernate Validator can still find a validator implementation class for each built-in constraint, despite the validatedBy is empty, but if I leave the

Spring validator: having both annotation and validator implementation

冷暖自知 提交于 2019-12-04 07:03:14
Is it possible to have both a validator for a form and annotation constraints? For example to have in a form object this field: @NotEmpty private String date; but then validate the date's pattern in a validator. I know there is the pattern annotation but I just want to see if I can use both types of validating. Here is the link to a very good site where it's explained how you can combine the JSR-303 validator with the spring validator. I'll present next my solution that works. Hope it helps. My abstract Validator: import java.util.Map; import java.util.Set; import javax.validation

How to get the Invalid value in the error message while using custom validator in spring?

若如初见. 提交于 2019-12-04 07:02:41
问题 I having trouble in showing Invalid value in the error message I have messages.properties file as follows ProductId.exists.custom.validator.validation = A product already exists with product id ${validatedValue}. and following is my custom validtor interface @Target( { METHOD, FIELD, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = ProductIdValidator.class) @Documented public @interface ProductId { String message() default "{ProductId.exists.custom.validator.validation}";

How to inject spring bean into Validator(hibernate)

可紊 提交于 2019-12-04 05:03:15
问题 spring doc I have read the following spring documentation: By default, the LocalValidatorFactoryBean configures a SpringConstraintValidatorFactory that uses Spring to create ConstraintValidator instances. This allows your custom ConstraintValidators to benefit from dependency injection like any other Spring bean. I have wrote custom validator: public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Object>{ @Autowired MyBeanDao dao; ... } But in debug I see that dao is

javax.validation.NotBlank missing validator

老子叫甜甜 提交于 2019-12-04 04:29:35
I have requirement that in common api module(multi module project) I can't use any kind of hibernate's validation annotations, so I did use one from javax.validation which is acceptable. Problem starts when I want to validate my domain objects(I use vaadin) that contains NotBlank annotation. I get the following exception javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'name' Validation is invoked by call Validation.buildDefaultValidatorFactory()

Validation for generated JAXB Classes (JSR 303 / Spring)

删除回忆录丶 提交于 2019-12-04 03:13:14
I Generated domain objects from schema (request & response) using JAXB (maven-jaxb2-plugin) I would like add validations (notnull /empty) for couple of attributes. I would like to have custom Bean Validation, the application is a REST service, i'm using Spring 3 and JSR 303 but i dont think i can use JSR 303 to validate the object as it is generated from the schema. can someone give me a nudge in the right direction on how to get this done. We've been using the Krasa JAXB plugin to generate JSR 303-annotated model beans from XSD files, and then telling Spring to automatically validate the

Cross field bean validation - why you no work

巧了我就是萌 提交于 2019-12-04 02:39:00
问题 I've got a little problem here with my application. I'd like to check if fields password and confirm password match together, so I tried to do it like in the first answer for this question: Cross field validation with Hibernate Validator (JSR 303) The problem is that it actually doesn't work and I HAVE NO IDEA WHY. Please, help me! This is my first post here, so please don't be too harsh for me. Here's my Annotation : /* * To change this template, choose Tools | Templates * and open the

Spring MVC with hibernate Validator to validate single basic type

自闭症网瘾萝莉.ら 提交于 2019-12-03 23:41:59
Below is the mapped method that I am having trouble with, no matter what value I pass to it the validation returns "passed validation." @RequestMapping(value = "test", method = RequestMethod.POST) @ResponseBody public String getTest(@RequestBody @Valid @Max(32) long longValue, BindingResult result) { if (result.hasErrors()) { return "failed validation"; } else { return "passed validation"; } } I know the @Max works with my application because I use it for validation on custom objects that return a lot of data to the controller. It only doesn't run the validation in this case where I call

How to solve NoSuchMethodError for javax.validation when deploying a spring boot application in weblogic server?

拜拜、爱过 提交于 2019-12-03 21:14:20
I am trying to deploy a simple spring boot application that will expose some rest api and I use hibernate entity manager to manipulate entity objects. When I try to deploy this application to Oracle Weblogic 12c, I get the following exception: <Jan 11, 2016 6:20:14 PM BDT> <Error> <Console> <BEA-240003> <Administration Console encountered the following error: weblogic.application.ModuleException: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider; at weblogic.application.internal.ExtensibleModuleWrapper.start