你的位置:首页 > Java教程

[Java教程]javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found


  1 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is 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.
  2 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
  3 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
  4 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
  5 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
  6 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
  7 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
  8 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
  9 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
 10 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
 11 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
 12 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
 13 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
 14 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
 15 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
 16 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
 17 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
 18 at javax.servlet.GenericServlet.init(GenericServlet.java:158)
 19 at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
 20 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
 21 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
 22 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4914)
 23 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5201)
 24 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 25 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
 26 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
 27 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
 28 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1101)
 29 at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1786)
 30 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
 31 at java.util.concurrent.FutureTask.run(FutureTask.java:262)
 32 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 33 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 34 at java.lang.Thread.run(Thread.java:744)
 35 Caused by: 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.
 36 at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
 37 at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:184)
 38 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
 39 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
 40 ... 32 more
 41 七月 18, 2015 2:18:16 下午 org.apache.catalina.core.StandardContext loadOnStartup
 42 严重: Servlet [spring] in web application [/Purchase] threw load() exception
 43 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.
 44 at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
 45 at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:184)
 46 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
 47 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
 48 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 49 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 50 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
 51 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
 52 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
 53 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
 54 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
 55 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
 56 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
 57 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
 58 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
 59 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
 60 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
 61 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
 62 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
 63 at javax.servlet.GenericServlet.init(GenericServlet.java:158)
 64 at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
 65 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
 66 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
 67 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4914)
 68 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5201)
 69 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 70 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
 71 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
 72 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
 73 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1101)
 74 at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1786)
 75 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
 76 at java.util.concurrent.FutureTask.run(FutureTask.java:262)
 77 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 78 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 79 at java.lang.Thread.run(Thread.java:744)
 80 七月 18, 2015 2:18:16 下午 org.apache.catalina.startup.HostConfig deployDirectory
 81 信息: Deployment of web application directory C:\Program Files\apache-tomcat-8.0.24\webapps\Purchase has finished in 5,278 ms
 82 七月 18, 2015 2:18:16 下午 org.apache.catalina.startup.HostConfig deployDirectory
 83 信息: Deploying web application directory C:\Program Files\apache-tomcat-8.0.24\webapps\ROOT
 84 七月 18, 2015 2:18:16 下午 org.apache.catalina.startup.HostConfig deployDirectory
 85 信息: Deployment of web application directory C:\Program Files\apache-tomcat-8.0.24\webapps\ROOT has finished in 45 ms
 86 2015-07-18 14:18:15,993 [localhost-startStop-1] ERROR [org.springframework.web.servlet.DispatcherServlet] - Context initialization failed
 87 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is 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.
 88 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
 89 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
 90 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 91 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
 92 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
 93 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
 94 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
 95 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
 96 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
 97 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
 98 at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
 99 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
100 at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
101 at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
102 at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
103 at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
104 at javax.servlet.GenericServlet.init(GenericServlet.java:158)
105 at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
106 at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
107 at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
108 at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4914)
109 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5201)
110 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
111 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
112 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
113 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
114 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1101)
115 at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1786)
116 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
117 at java.util.concurrent.FutureTask.run(FutureTask.java:262)
118 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
119 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
120 at java.lang.Thread.run(Thread.java:744)
121 Caused by: 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.
122 at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:271)
123 at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:184)
124 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
125 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
126 ... 32 more

解决方法:添加jsr303-validation包或者添加maven包的依赖

<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
<version>0.5</version>
</dependency>