-
Notifications
You must be signed in to change notification settings - Fork 322
Application fails to start with "No target ValidatorFactory set" when validation API is present without provider #1407
Copy link
Copy link
Closed
Labels
in: coreIssues related to config and core supportIssues related to config and core supportstatus: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: bugA general bugA general bug
Milestone
Description
Summary
After upgrading from Spring Boot 3.5.x to Spring Boot 4.0.x, an application using Spring GraphQL fails to start if jakarta.validation-api is on the classpath (as a transitive dependency) but no validation provider (Hibernate Validator) is present.
This worked in Spring Boot 3.5.x / Spring GraphQL 1.3.x.
Environment
- Spring Boot: 4.0.1
- Spring GraphQL: 2.0.1
- Java: 21
Behavior
The logs show OptionalValidatorFactoryBean detecting the missing provider:
INFO o.s.v.b.OptionalValidatorFactoryBean : Failed to set up a Bean Validation provider: jakarta.validation.NoProviderFoundException: Unable to create a Configuration, because no Jakarta Validation provider could be found.
But then the application fails:
Caused by: java.lang.IllegalStateException: No target ValidatorFactory set
at org.springframework.util.Assert.state(Assert.java:80)
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.getValidator(LocalValidatorFactoryBean.java:373)
at org.springframework.graphql.data.method.annotation.support.ValidationHelper.createIfValidatorPresent(ValidationHelper.java:123)
at org.springframework.graphql.data.method.annotation.support.AnnotatedControllerConfigurer.afterPropertiesSet(AnnotatedControllerConfigurer.java:157)
Workarounds
Either of these allows the application to start:
- Add
spring-boot-starter-validation(provides Hibernate Validator) - Exclude
jakarta.validation-apifrom the transitive dependency
In my case, jakarta.validation-api comes from:
org.keycloak:keycloak-admin-client
└── org.jboss.resteasy:resteasy-core-spi
└── jakarta.validation:jakarta.validation-api:3.1.1
Notes
I'm not certain whether this is a spring-graphql issue or should be handled elsewhere (spring-boot auto-configuration?). Happy to move it if needed.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in: coreIssues related to config and core supportIssues related to config and core supportstatus: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: bugA general bugA general bug