Error "IllegalStateException: No target Validator set" after upgrade from Spring Boot 3.1.5 to 3.2.0
Asked Answered
S

1

8

After upgrading a reactive application from Spring Boot 3.1.5 to Spring Boot 3.2.0, I get the following error:

java.lang.IllegalStateException: No target Validator set
    at org.springframework.util.Assert.state(Assert.java:76)
    at org.springframework.validation.beanvalidation.SpringValidatorAdapter.forExecutables(SpringValidatorAdapter.java:396)
    at org.springframework.validation.beanvalidation.MethodValidationAdapter.invokeValidatorForArguments(MethodValidationAdapter.java:257)
    at org.springframework.validation.beanvalidation.MethodValidationAdapter.validateArguments(MethodValidationAdapter.java:240)
    at org.springframework.web.method.annotation.HandlerMethodValidator.validateArguments(HandlerMethodValidator.java:115)
    at org.springframework.web.method.annotation.HandlerMethodValidator.applyArgumentValidation(HandlerMethodValidator.java:83)
    at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$invoke$0(InvocableHandlerMethod.java:164)
    ...

There is no other change in the code, the exception did not occur before in Spring Boot 3.1.5.

Spongy answered 24/11, 2023 at 20:33 Comment(0)
S
18

It is caused by a change of logic in the dependency on spring-boot-starter-validation. In my Spring Boot 3.1.5 applications, I either had not this dependency at all, or had it with the test scope. Now in spring Boot 3.2.0 it is apparently mandatory. The pom.xml file must contain

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

Without this, any controller method with parameters annotated with some jakarta.validation.* annotations, such as jakarta.validation.constraints.NotNull, throws the described exception. The exception is thrown by Spring and the method is not even called at all.

Spongy answered 24/11, 2023 at 20:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.