Reputation: 25
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;
Upvotes: 0
Views: 1199
Reputation: 118
Everything seems fine just add @Validated annotation at Controller class level. I hope this works.
Upvotes: 0
Reputation: 246
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
Upvotes: 1