Caused by: java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider

问题现象:今天部署代码的时候发现,在beta环境可以正常部署,但是到了test环境就一直不成功,我以为是环境问题,就重新部署,但是没效,看了看日志发现问题是:Caused by: java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider

2019-02-18 11:31:18,732 main ERROR (DispatcherServlet:502) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/validation/valueextraction/ValueExtractorDeclarationException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1634) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668) ~[spring-webmvc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634) ~[spring-webmvc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682) ~[spring-webmvc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553) ~[spring-webmvc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) [spring-webmvc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171) [spring-webmvc-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at javax.servlet.GenericServlet.init(GenericServlet.java:244) [javax.servlet-api-3.1.0.jar:3.1.0]
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:612) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:395) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:871) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1345) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1338) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:501) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.server.Server.start(Server.java:387) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.server.Server.doStart(Server.java:354) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
    at com.sankuai.mms.boot.AbstractBootstrap.start(AbstractBootstrap.java:139) [mms-boot-jetty9-1.2.2.jar:?]
    at com.sankuai.mms.boot.AbstractBootstrap.boot(AbstractBootstrap.java:66) [mms-boot-jetty9-1.2.2.jar:?]
    at com.sankuai.mms.boot.Bootstrap.main(Bootstrap.java:28) [mms-boot-jetty9-1.2.2.jar:?]
Caused by: java.lang.NoClassDefFoundError: javax/validation/valueextraction/ValueExtractorDeclarationException
    at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:33) ~[hibernate-validator-6.0.5.Final.jar:6.0.5.Final]
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276) ~[validation-api-1.1.0.Final.jar:?]
    at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:255) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean.afterPropertiesSet(OptionalValidatorFactoryBean.java:40) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1692) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1630) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    ... 42 more
Caused by: java.lang.ClassNotFoundException: javax.validation.valueextraction.ValueExtractorDeclarationException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_45]
    at org.eclipse.jetty.webapp.WebAppClassLoader.findClass(WebAppClassLoader.java:510) ~[jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:441) ~[jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403) ~[jetty-all-9.2.6.v20141205.jar:9.2.6.v20141205]
    at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:33) ~[hibernate-validator-6.0.5.Final.jar:6.0.5.Final]
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276) ~[validation-api-1.1.0.Final.jar:?]
    at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:255) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean.afterPropertiesSet(OptionalValidatorFactoryBean.java:40) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1692) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1630) ~[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    ... 42 more
View Code

 

问题原因:

简单查了一下,是由于jar包hibernate-validator、validation-api 不兼容。

版本分别为:

               <groupId>org.hibernate.validator</groupId>
               <artifactId>hibernate-validator</artifactId>
               <version>6.0.5.Final</version>

                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
                <version>1.1.0.Final</version>

 

解决方案1:

升级validation-api的版本,目前hibernate-validator中对应的版本为 2.0.1.Final

版本分别为:

               <groupId>org.hibernate.validator</groupId>
               <artifactId>hibernate-validator</artifactId>
               <version>6.0.5.Final</version>

                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
                <version>2.0.1.Final</version>

 

解决方案2:

降级hibernate-validator的版本,hibernate-validator对应的版本为 5.1.3.Final

版本分别为:

               <groupId>org.hibernate.validator</groupId>
               <artifactId>hibernate-validator</artifactId>
               <version>5.1.3.Final</version>

                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
                <version>1.1.0.Final</version>

 

posted @ 2019-02-18 11:48  selicoco  阅读(7185)  评论(2编辑  收藏  举报