Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

java - Spring Boot - Validations stopped working after upgrade from 2.2.5 to 2.3.0

I've migrated a Spring Boot project from 2.2.5 to 2.3.0 and after that, Validations stopped to work (they aren't invoked at all).

I read in changelog documentation (https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3.0-M1-Release-Notes), that spring-boot-starter-validation now needs to be added manually as a dependency.

So, I added it to my pom.xml:

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

My pom parent is:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.0.RELEASE</version>
    <relativePath></relativePath>
</parent>

My Controller looks like this:

@PostMapping( value = "/signup", consumes = MediaType.APPLICATION_JSON_VALUE )
@ResponseStatus( value = HttpStatus.OK )
public void signUp( @Valid @RequestBody ClientDto clientDto )
{
    onboardingService.signUp( clientDto );
}

EDIT:

I WAS ABLE TO FOUND THE ISSUE, CHECK MY ANSWER BELOW!

Thanks everybody for the help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Validation starter not included in web starters anymore.

The spring-boot-starter-validation is not a transitive dependency of spring-boot-starter-web and spring-boot-starter-webflux anymore.

Add this dependency for validations work.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...