Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath

Today,I am looking into send Email, but when I add

<dependency>     <groupId>org.springframework</groupId>     <artifactId>spring-context-support</artifactId>     <version>4.2.5.RELEASE</version> </dependency>  <dependency>     <groupId>javax</groupId>     <artifactId>javaee-api</artifactId>     <version>7.0</version> </dependency>  <dependency>     <groupId>javax.mail</groupId>     <artifactId>javax.mail-api</artifactId>     <version>1.5.5</version> </dependency> 

to pom.xml and deploy on the server, I get an " Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath." validation exception.

I'm just added the dependency above and the one for email to a template MVC project.

Error stacktrace:

DEBUG: org.springframework.ui.context.support.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.DelegatingThemeSource@20212230] DEBUG: org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean - Failed to set up a Bean Validation provider javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.     at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)     at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:223)     at org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean.afterPropertiesSet(OptionalValidatorFactoryBean.java:40)     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)     at javax.servlet.GenericServlet.init(GenericServlet.java:158)     at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)     at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)     at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4944)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)     at java.util.concurrent.FutureTask.run(FutureTask.java:266)     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)     at java.lang.Thread.run(Thread.java:745) 
like image 259
BluntFish Avatar asked Mar 31 '16 09:03

BluntFish


People also ask

What is Hibernate Validator?

Hibernate Validator allows to express and validate application constraints. The default metadata source are annotations, with the ability to override and extend through the use of XML. It is not tied to a specific application tier or programming model and is available for both server and client application programming.

Is Hibernate Validator thread safe?

Validating constraints In the setUp() method, a Validator instance is retrieved from the ValidatorFactory . Validator instances are thread-safe and may be reused multiple times. The validate() method returns a set of ConstraintViolation instances, which you can iterate in order to see which validation errors occurred.

What is @valid Annotation in spring boot?

The @Valid annotation ensures the validation of the whole object. Importantly, it performs the validation of the whole object graph. However, this creates issues for scenarios needing only partial validation. On the other hand, we can use @Validated for group validation, including the above partial validation.

What is Jakarta validation API?

Jakarta Bean Validation is a Java specification which. lets you express constraints on object models via annotations. lets you write custom constraints in an extensible way. provides the APIs to validate objects and object graphs. provides the APIs to validate parameters and return values of methods and constructors.


2 Answers

Add a Bean Validation Provider dependency e.g Hibernate Validator. The Bean Validation API dependency is available on the classpath but the implementation is missing. Add the following to your pom.xml

<dependency>     <groupId>org.hibernate</groupId>     <artifactId>hibernate-validator</artifactId>     <version>5.2.4.Final</version> </dependency> 
like image 138
ekem chitsiga Avatar answered Sep 29 '22 12:09

ekem chitsiga


To resolve the same issue in Spring Boot, add following dependency to your project

implementation 'org.springframework.boot:spring-boot-starter-validation' 
like image 24
Andrey Chertok Avatar answered Sep 29 '22 12:09

Andrey Chertok