您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发

【原】java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String

不忘初心 不忘初心 2020-10-01 围观() 评论() 点赞() JAVA开发

简介:在升级个人博客的校验框架到hibernate-validator的过程中,还碰见了另外一个问题:“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.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String”,也是因为那个javaee-api包的缘故。

在升级个人博客的校验框架到hibernate-validator的过程中,还碰见了另外一个问题:“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.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String”,也是因为那个javaee-api包的缘故。

详细错误信息如下:

2020-09-17 23:31:05 [ INFO] - org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.13.Final
2020-09-17 23:31:06 [ERROR] - org.springframework.web.servlet.DispatcherServlet - 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.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1589)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
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:759)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
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:1144)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:985)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4875)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1719)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:286)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:479)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:428)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:286)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at java.security.AccessController.doPrivileged(Native Method)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;
at org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters.<init>(ValidationBootstrapParameters.java:63)
at org.hibernate.validator.internal.engine.ConfigurationImpl.parseValidationXml(ConfigurationImpl.java:540)
at org.hibernate.validator.internal.engine.ConfigurationImpl.buildValidatorFactory(ConfigurationImpl.java:337)
at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:303)
at org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean.afterPropertiesSet(OptionalValidatorFactoryBean.java:40)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1648)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1585)
... 66 more

打开BootstrapConfiguration.java类找了一下,里面确实没有这个API

/*
* Copyright 2012-2013, Red Hat, Inc. and/or its affiliates, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package javax.validation;
import java.util.Map;
import java.util.Set;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;
import javax.validation.spi.ValidationProvider;
/**
* Represents the user specified default configuration in
* {
@code META-INF/validation.xml}.
* <p/>
* Note that modifications to the returned objects do not have any effect.
* Instead use the methods provided on {
@link Configuration} in order to
* apply modifications to the configuration.
*
*
@author Emmanuel Bernard
*
@author Gunnar Morling
*
@author Hardy Ferentschik
*
@since 1.1
*/

public interface BootstrapConfiguration {
/**
* Class name of the {
@link ValidationProvider} implementation
* or {
@code null} if none is specified.
*
*
@return validation provider class name
*/

String getDefaultProviderClassName();
/**
* Class name of the {
@link ConstraintValidatorFactory} implementation
* or {
@code null} if none is specified.
*
*
@return constraint validator factory class name
*/

String getConstraintValidatorFactoryClassName();
/**
* Class name of the {
@link MessageInterpolator} implementation
* or {
@code null} if none is specified.
*
*
@return message interpolator class name or {@code null}
*/

String getMessageInterpolatorClassName();
/**
* Class name of the {
@link TraversableResolver} implementation
* or {
@code null} if none is specified.
*
*
@return traversable resolver class name or {@code null}
*/

String getTraversableResolverClassName();
/**
* Class name of the {
@link ParameterNameProvider} implementation
* or {
@code null} if none is specified.
*
*
@return parameter name provider class name or {@code null}
*/

String getParameterNameProviderClassName();
/**
* Returns a set of resource paths pointing to XML constraint mapping files.
* The set is empty if none are specified.
*
*
@return set of constraint mapping resource paths
*/

Set<String> getConstraintMappingResourcePaths();
/**
* Returns true if the validation execution is explicitly marked as enabled
* or if it is left undefined.
*
*
@return whether validation execution is globally enabled
*/

boolean isExecutableValidationEnabled();
/**
* Returns the set of executable types that should be considered
* unless explicitly overridden via {
@link ValidateOnExecution}
* <p/>
* Returns a set containing {
@link ExecutableType#CONSTRUCTORS} and
* {
@link ExecutableType#NON_GETTER_METHODS} if unspecified in the configuration.
*
*
@return set of validated executable types
*/

Set<ExecutableType> getDefaultValidatedExecutableTypes();
/**
* Returns properties as a map of string based key/value pairs.
* The map is empty if no property has been specified.
*
*
@return the properties map
*/

Map<String, String> getProperties();
}

摸索了一番才发现,是因为javaee-api包的版本过低,需要将其升级到8.0版本(我的博客中是7.0版本)。

<!-- javaee-api和hibernate-validator有一些冲突,需要升级到8.0才可以兼容6.0.13版本的hibernate-validator -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<!-- 需要升级到8.0版本 -->
<version>7.0</version>
</dependency>

8.0包中的BootstrapConfiguration.java类,就已经可以找到getClockProviderClassName()方法了。

java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String

详细API如下:

/*
* Bean Validation API
*
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/

package javax.validation;
import java.util.Map;
import java.util.Set;
import javax.validation.executable.ExecutableType;
import javax.validation.executable.ValidateOnExecution;
import javax.validation.spi.ValidationProvider;
import javax.validation.valueextraction.ValueExtractor;
/**
* Represents the user specified default configuration in
* {
@code META-INF/validation.xml}.
* <p>
* Note that modifications to the returned objects do not have any effect.
* Instead use the methods provided on {
@link Configuration} in order to
* apply modifications to the configuration.
*
*
@author Emmanuel Bernard
*
@author Gunnar Morling
*
@author Hardy Ferentschik
*
@author Guillaume Smet
*
@since 1.1
*/

public interface BootstrapConfiguration {
/**
* Class name of the {
@link ValidationProvider} implementation
* or {
@code null} if none is specified.
*
*
@return validation provider class name
*/

String getDefaultProviderClassName();
/**
* Class name of the {
@link ConstraintValidatorFactory} implementation
* or {
@code null} if none is specified.
*
*
@return constraint validator factory class name
*/

String getConstraintValidatorFactoryClassName();
/**
* Class name of the {
@link MessageInterpolator} implementation
* or {
@code null} if none is specified.
*
*
@return message interpolator class name or {@code null}
*/

String getMessageInterpolatorClassName();
/**
* Class name of the {
@link TraversableResolver} implementation
* or {
@code null} if none is specified.
*
*
@return traversable resolver class name or {@code null}
*/

String getTraversableResolverClassName();
/**
* Class name of the {
@link ParameterNameProvider} implementation
* or {
@code null} if none is specified.
*
*
@return parameter name provider class name or {@code null}
*/

String getParameterNameProviderClassName();
/**
* Class name of the {
@link ClockProvider} implementation or
* {
@code null} if none is specified.
*
*
@return clock provider class name or {@code null}
*
*
@since 2.0
*/

String getClockProviderClassName();
/**
* Returns the class names of {
@link ValueExtractor}s.
*
*
@return the value extractor class names or an empty set if none are specified
*
@since 2.0
*/

Set<String> getValueExtractorClassNames();
/**
* Returns a set of resource paths pointing to XML constraint mapping files.
* The set is empty if none are specified.
*
*
@return set of constraint mapping resource paths
*/

Set<String> getConstraintMappingResourcePaths();
/**
* Returns true if the validation execution is explicitly marked as enabled
* or if it is left undefined.
*
*
@return whether validation execution is globally enabled
*/

boolean isExecutableValidationEnabled();
/**
* Returns the set of executable types that should be considered
* unless explicitly overridden via {
@link ValidateOnExecution}
* <p>
* Returns a set containing {
@link ExecutableType#CONSTRUCTORS} and
* {
@link ExecutableType#NON_GETTER_METHODS} if unspecified in the configuration.
*
*
@return set of validated executable types
*/

Set<ExecutableType> getDefaultValidatedExecutableTypes();
/**
* Returns properties as a map of string based key/value pairs.
* The map is empty if no property has been specified.
*
*
@return the properties map
*/

Map<String, String> getProperties();
}

springspringmvcvalidator

看完文章,有任何疑问,请加入群聊一起交流!!!

很赞哦! ()

文章评论

  • 请先说点什么
    人参与,条评论

请使用电脑浏览器访问本页面,使用手机浏览器访问本页面会导致下载文件异常!!!

雨落无影

关注上方公众号,回复关键字【下载】获取下载码

用完即删,每次下载需重新获取下载码

若出现下载不了的情况,请及时联系站长进行解决

站点信息

  • 网站程序:spring + freemarker
  • 主题模板:《今夕何夕》
  • 文章统计:篇文章
  • 标签管理标签云
  • 微信公众号:扫描二维码,关注我们