解决办法1
一般这种错误都是重复引入包了,看具体报错的是哪个类,把这个依赖注释掉


解决办法2

  • 第二天的时候,发现了真实的原因,其实重复引入包会报错,这个说法是不严谨的。
  • 最大的问题是在于包版本的问题,我们使用的hibernate-validator默认版本号是6.x,对应java的validation-api的版本应该是2.x,我这里强制指定了1.x,版本没对上。
  • 其实在spring-boot的项目中,我们没必要指定validation-api的版本,直接使用spring-boot的默认版本声明就可以了。
  • 去掉版本号声明以后,我们看到会默认引入的版本是2.x,然后启动,就不会报错了

比如我的完整报错是: Correct the classpath of your application so that it contains compatible versions of the classes org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters and javax.validation.BootstrapConfiguration

ValidationBootstrapParameters是hibernate-validator包里的,因为spring-boot-web-starter默认引入了,我这里其实就不需要引入了。

注释掉这个依赖,ok,问题解决


完整报错信息:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters.<init>(ValidationBootstrapParameters.java:65)

The following method did not exist:

    javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;

The calling method's class, org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters, was loaded from the following location:

    jar:file:/Users/albert/code/repo/org/hibernate/validator/hibernate-validator/6.2.0.Final/hibernate-validator-6.2.0.Final.jar!/org/hibernate/validator/internal/xml/config/ValidationBootstrapParameters.class

The called method's class, javax.validation.BootstrapConfiguration, is available from the following locations:

    jar:file:/Users/albert/code/repo/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar!/javax/validation/BootstrapConfiguration.class
    jar:file:/Users/albert/code/repo/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar!/javax/validation/BootstrapConfiguration.class
    jar:file:/Users/albert/code/repo/javax/javaee-api/8.0/javaee-api-8.0.jar!/javax/validation/BootstrapConfiguration.class

The called method's class hierarchy was loaded from the following locations:

    javax.validation.BootstrapConfiguration: file:/Users/albert/code/repo/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.hibernate.validator.internal.xml.config.ValidationBootstrapParameters and javax.validation.BootstrapConfiguration


Process finished with exit code 1

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐