hibernate-validator

How to test if @Valid annotation is working?

落花浮王杯 提交于 2020-08-24 11:27:40
问题 I have the following unit test: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {EqualblogApplication.class}) @WebAppConfiguration @TestPropertySource("classpath:application-test.properties") public class PostServiceTest { // ... @Test(expected = ConstraintViolationException.class) public void testInvalidTitle() { postService.save(new Post()); // no title } } The code for save in PostService is: public Post save(@Valid Post post) { return postRepository.save

How to test if @Valid annotation is working?

ぃ、小莉子 提交于 2020-08-24 11:26:32
问题 I have the following unit test: @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = {EqualblogApplication.class}) @WebAppConfiguration @TestPropertySource("classpath:application-test.properties") public class PostServiceTest { // ... @Test(expected = ConstraintViolationException.class) public void testInvalidTitle() { postService.save(new Post()); // no title } } The code for save in PostService is: public Post save(@Valid Post post) { return postRepository.save

Hibernate Validator in Spring Boot using different ConstraintValidatorManager

喜夏-厌秋 提交于 2020-06-28 08:26:23
问题 I am facing an issue that has been mentioned before with Spring Boot vs. Hibernate Validation, where autowiring of dependencies inside custom Constraint Validators is not working. From my own debugging, I have noticed that when entity-level validation occurs, Hibernate loads a different ConstraintValidatorManager compared to when Hibernate is performing bean validation for form submits. The latter works fine, the former leads to dependencies of the custom Constraint Validator being null. It

spring mvc @RequestPart validation via annotation

冷暖自知 提交于 2020-06-26 19:44:01
问题 How can I validate that the body request part is not empty? @PostMapping("/messages") @ResponseStatus(HttpStatus.CREATED) fun createMessage(@Valid @RequestPart message: MessageCreate, @Valid @RequestPart @NotEmpty body: MultipartFile, @RequestParam attachments: List<MultipartFile>) { return service.create(message, body, attachments) } I tried to create a custom validator annotation that checks body.isEmpty() result but it has no effect. What is missing ? Is it possible do to it this way ? 回答1

java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName

会有一股神秘感。 提交于 2020-06-13 15:29:47
问题 JDK: 1.8.0_131 Tomcat: 8.0.27.0 Hibernate Validator: 6.0.7.Final + all the dependencies downloaded from: Hibernate Validator 6 @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public AccountSyncResponse excute(AccountSyncRequest account_sync_request_) { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<AccountSyncRequest>> violations = validator.validate(account_sync

spring3 mvc @Valid annotation cannot be found

自古美人都是妖i 提交于 2020-05-31 07:00:12
问题 I try to use @Valid annotation, but eclipse always gives the "Valid cannot be resolved to a type" error. I m using the spring3 library. I have imported hibernate-validator-4.1.0.Final.jar into my WEB-INF/lib directory. however, this does not solve the problem. Any help is appreciated! 回答1: As far as I remember the @Valid annotation is part of the validation-api JAR which you can find in the lib directory of the Hibernate Validator, as you have already downloaded the Hibernate implementation.

spring3 mvc @Valid annotation cannot be found

拜拜、爱过 提交于 2020-05-31 06:56:20
问题 I try to use @Valid annotation, but eclipse always gives the "Valid cannot be resolved to a type" error. I m using the spring3 library. I have imported hibernate-validator-4.1.0.Final.jar into my WEB-INF/lib directory. however, this does not solve the problem. Any help is appreciated! 回答1: As far as I remember the @Valid annotation is part of the validation-api JAR which you can find in the lib directory of the Hibernate Validator, as you have already downloaded the Hibernate implementation.

Spring MVC with hibernate validation doesn't work

对着背影说爱祢 提交于 2020-05-15 08:30:06
问题 I have some problems with hibernate validations with Spring. I did everything as explained in an online tutorial, but it's not working and I just go to the next page without validation error. import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; public class Customer { private String firstName; @NotNull() @Size(min=1, message = "this field must not to be empty") private String lastName; Controller: @RequestMapping("/processForm") public String processForm(

What alternatives are there to Hibernate Validator's @SafeHtml to validate Strings?

北慕城南 提交于 2020-05-14 16:16:52
问题 As stated in the JavaDocs, it will be removed in a future release. Is there any alternative library which works similarly via annotations? 回答1: Let's first explain the reasons of the deprecation: we recently had a security issue (CVE) due to this very constraint. It was due to an error in our implementation but it made us realize that this was very fragile and potentially a can of worms security wise. The alternative for now would be to implement it yourself based on our latest implementation

What alternatives are there to Hibernate Validator's @SafeHtml to validate Strings?

我是研究僧i 提交于 2020-05-14 16:13:08
问题 As stated in the JavaDocs, it will be removed in a future release. Is there any alternative library which works similarly via annotations? 回答1: Let's first explain the reasons of the deprecation: we recently had a security issue (CVE) due to this very constraint. It was due to an error in our implementation but it made us realize that this was very fragile and potentially a can of worms security wise. The alternative for now would be to implement it yourself based on our latest implementation