0

I have the following dependency in the pom.xml for spring boot validation and controller method argument updated with @Valid annotation but still no validation errors when I submit a request with null or not empty values. Any Idea like why validation not getting trigged even though hibernate validation library on the classpath.

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>

  @RequestMapping("hello")
    public ResponseEntity<String> message(@Valid @RequestBody MyRequest request)
    {





 public class MyRequest {
    @NotNull(message = "Client ID is mandatory")
    @NotEmpty
    private String clientId;

    @NotEmpty private String employId;
1
  • What happens when you submit a request with data not following the validation rules? Do you at least see a 404 BAD request status? Commented Jun 29, 2021 at 20:58

2 Answers 2

1

anotations @NotEmpty and @NotNull and @Valid must be imported from javax.validation .... They are all in the jakarta.Validation api specifications otherwise it won't work

Sign up to request clarification or add additional context in comments.

1 Comment

I am doing the imports from javax.validation.constraints.* package but still same issue.
0

Everything seems fine just add @Validated annotation at Controller class level. I hope this works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.