Maven使用错误版本的javax.validation [英] Maven using wrong version of javax.validation

查看:4980
本文介绍了Maven使用错误版本的javax.validation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用hibernate作为jpa提供程序的动态web项目。直到上周,我可以使用hibernate插入,更新,查询和从我的数据库中删除。最近,我开始研究验证,并引入了很多不同的Maven依赖关系。在这样做的过程中,我不知何故已经结束了我的项目使用javax.validation jar的旧版本,它抛出了一个没有这样的方法异常。我已经包含了以下堆栈跟踪的相关行:

 引起:java.lang.NoSuchMethodError:javax.validation.BootstrapConfiguration .getClockProviderClassName()Ljava /郎/字符串; 
at org.hibernate.validator.internal.xml.ValidationBootstrapParameters。< init>(ValidationBootstrapParameters.java:63)

但是,在我的pom.xml中,我有以下依赖项(当通过javap和eclipse检查时,它在指定的类中具有getClockProviderClassName()方法):

 <! -  https://mvnrepository.com/artifact/javax.validation/validation-api  - > 
< dependency>
< groupId> javax.validation< / groupId>
< artifactId> validation-api< / artifactId>
< version> 2.0.0.Final< / version>
< /依赖关系>

我将以下排除标记放在我的pom中的多个依赖项中,以确保它不会拉这个来自其他来源的jar:

 < exclusion> 
< artifactId> validation-api< / artifactId>
< groupId> javax.validation< / groupId>
< /排除>

我也简化了构建路径,所以它有三个元素:一个属性文件夹,它包含只有我的log4j配置,JRE系统库(版本1.8)和maven依赖项。有什么方法可以告诉已过时的javax.validation jar来自哪里?我是否可以强制程序使用使用maven引入的2.0.0版本?感谢您的帮助。



其他信息:

完整堆栈跟踪

persistence.xml源文件

工作数据源属性

Java构建路径



行中发生根异常(在我的代码中)



查看包含的jar文件,看看它是否包含该方法



使用javap检查maven(m2)目录中的工件



来自maven的依赖关系概述



来自pom.xml的依赖关系

 <依赖关系> 
<! - https://mvnrepository.com/artifact/org.springframework/spring-core - >
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-core< / artifactId>
< version> 5.0.2.RELEASE< / version>
<排除项>
<排除>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< /排除>
< /排除>
< /依赖关系>
<! - https://mvnrepository.com/artifact/org.hibernate/hibernate-core - >
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 5.2.2.Final< / version>
<排除项>
<排除>
< artifactId> jboss-logging< / artifactId>
< groupId> org.jboss.logging< / groupId>
< /排除>
<排除>
< artifactId> validation-api< / artifactId>
< groupId> javax.validation< / groupId>
< /排除>
< /排除>
< /依赖关系>
<! - https://mvnrepository.com/artifact/mysql/mysql-connector-java - >
< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< version> 6.0.3< / version>
< /依赖关系>
<! - https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core - >
< dependency>
< groupId> org.apache.logging.log4j< / groupId>
< artifactId> log4j-core< / artifactId>
< version> 2.10.0< / version>
< /依赖关系>
<! - https://stackoverflow.com/questions/20859379/cannot-import-javax-ejb-packages - >
< dependency>
< groupId> javax< / groupId>
< artifactId> javaee-api< / artifactId>
< version> 7.0< / version>
< /依赖关系>
< dependency>
< groupId> javax< / groupId>
< artifactId> javaee-web-api< / artifactId>
< version> 6.0< / version>
< scope>提供< / scope>
< /依赖关系>
<! - https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging - >
< dependency>
< groupId> org.jboss.logging< / groupId>
< artifactId> jboss-logging< / artifactId>
< version> 3.3.0.Final< / version>
< /依赖关系>
<! - https://mvnrepository.com/artifact/javax.ejb/ejb-api - >
< dependency>
< groupId> javax.ejb< / groupId>
< artifactId> ejb-api< / artifactId>
< version> 3.0< / version>
< scope>提供< / scope>
< /依赖关系>
<! - https://mvnrepository.com/artifact/org.springframework/spring-webmvc - >
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-webmvc< / artifactId>
< version> 5.0.2.RELEASE< / version>
< /依赖关系>
<! - https://mvnrepository.com/artifact/javax.servlet/servlet-api - >
< dependency>
< groupId> javax.servlet< / groupId>
< artifactId> servlet-api< / artifactId>
< version> 3.0-alpha-1< / version>
< scope>提供< / scope>
< /依赖关系>
<! - https://mvnrepository.com/artifact/junit/junit - >
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.12< / version>
< scope> test< / scope>
< /依赖关系>
<! - https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind - >
< dependency>
< groupId> com.fasterxml.jackson.core< / groupId>
< artifactId> jackson-databind< / artifactId>
< version> 2.9.3< / version>
< /依赖关系>
<! - ***************************************** ************************************************** *************** - >
<! - 以下内容与用于将
连接到DB的独立于HIBERNATE相同,这些用于验证 - >
<! - https://mvnrepository.com/artifact/org.hibernate/hibernate-validator - >
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator< / artifactId>
< version> 6.0.7.Final< / version>
<排除项>
<排除>
< artifactId> validation-api< / artifactId>
< groupId> javax.validation< / groupId>
< /排除>
< /排除>
< /依赖关系>
<! - https://mvnrepository.com/artifact/org.hibernate/hibernate-validator-annotation-processor - >
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator-annotation-processor< / artifactId>
< version> 6.0.7.Final< / version>
<排除项>
<排除>
< artifactId> validation-api< / artifactId>
< groupId> javax.validation< / groupId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator-cdi< / artifactId>
< version> 6.0.7.Final< / version>
<排除项>
<排除>
< artifactId> validation-api< / artifactId>
< groupId> javax.validation< / groupId>
< /排除>
< /排除>
< /依赖关系>
<! - https://mvnrepository.com/artifact/javax.validation/validation-api - >
< dependency>
< groupId> javax.validation< / groupId>
< artifactId> validation-api< / artifactId>
< version> 2.0.0.Final< / version>
< /依赖关系>
<! - ***************************************** ************************************************** *************** - >
<! - html中的表达式语言{a.b}的API和参考实现
code - >
<! - https://mvnrepository.com/artifact/javax.el/javax.el-api - >
< dependency>
< groupId> javax.el< / groupId>
< artifactId> javax.el-api< / artifactId>
< version> 3.0.0< / version>
< /依赖关系>
<! - https://mvnrepository.com/artifact/org.glassfish.web/javax.el - >
< dependency>
< groupId> org.glassfish.web< / groupId>
< artifactId> javax.el< / artifactId>
< version> 2.2.6< / version>
< /依赖关系>
< /依赖关系>


解决方案

> javaee-web-api 7.0 作为依赖关系:

 < dependency> 
< groupId> javax< / groupId>
< artifactId> javaee-web-api< / artifactId>
< version> 7.0< / version>
< scope>提供< / scope>
< /依赖关系>

您的servlet或应用程序容器在运行时提供的这种依赖关系为您提供了一个较旧的api for <$ c

您有两件事情可以尝试:

javaee-web-api 的版本更改为8.0



这是如果您将Web应用程序部署到支持Java EE 8.0的servlet或应用程序容器(例如:似乎可以在Tomcat 8.5.X中工作,但阅读文档,只有Tomcat 9提供对Java EE 8的支持) / p>

保留> javaee-web-api 为7.0并降级 hibernate-validator validation-api 依赖关系:

 <依赖性> 
< groupId> javax.validation< / groupId>
< artifactId> validation-api< / artifactId>
< version> 1.1.0.Final< / version>
< /依赖关系>

< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator< / artifactId>
< version> 5.4.2.Final< / version>
< /依赖关系>

< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator-annotation-processor< / artifactId>
< version> 5.4.2.Final< / version>
< /依赖关系>

您还必须更改一些导入,例如 @Email @NotEmpty javax.validation 包到 org.hibernate.validator。约束(这些注释在6.0.X版本中已弃用,因为它们包含在 javax.validation api中)。


I have a dynamic web project I have been working on that uses hibernate as a jpa provider. Up until the last week, I could insert, update, query, and delete from my databases using hibernate. Recently, I began working on validation, and brought in a lot of different maven dependencies. In the course of doing this, I somehow have ended up with my project using an older, deprecated version of javax.validation jar, which throws a no such method exception. I have included the relevant lines of the stack trace below:

Caused by: java.lang.NoSuchMethodError: javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;
at org.hibernate.validator.internal.xml.ValidationBootstrapParameters.<init>(ValidationBootstrapParameters.java:63)

However, in my pom.xml I have the following dependency (which, when examined via javap and through eclipse, it has the method getClockProviderClassName() in the specified class):

<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.0.Final</version>
    </dependency>   

I put the following exclusion tag in my pom in multiple dependencies to try and ensure that it does not pull this jar from other sources:

            <exclusion>
                <artifactId>validation-api</artifactId>
                <groupId>javax.validation</groupId>
            </exclusion>

I have also simplified my build path, so there is three elements in it: one properties folder that contains only my log4j configuration, the JRE System library (version 1.8) and maven dependencies. Is there any way to tell where the deprecated javax.validation jar is coming from? Can I force the program to use version 2.0.0 I bring in with maven? Thank you for your help.

Additional Information:
full stack trace

persistence.xml source

working datasource properties

Java Build Path

Line where root exception occurs (in my code)

look inside the included jar to see it contains the method

using javap to examine artifact in maven (m2) directory

dependency overview from maven

Dependencies from pom.xml

<dependencies>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.0.2.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.2.Final</version>
        <exclusions>
            <exclusion>
                <artifactId>jboss-logging</artifactId>
                <groupId>org.jboss.logging</groupId>
            </exclusion>
            <exclusion>
                <artifactId>validation-api</artifactId>
                <groupId>javax.validation</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.10.0</version>
    </dependency>
    <!-- https://stackoverflow.com/questions/20859379/cannot-import-javax-ejb-packages -->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.3.0.Final</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.ejb/ejb-api -->
    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>ejb-api</artifactId>
        <version>3.0</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.0.2.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0-alpha-1</version>
        <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.3</version>
    </dependency>
    <!-- ********************************************************************************************************** -->
    <!-- THE FOLLOWING ARE SEPERATE FROM HIBERNATE THAT IS USED TO CONNECT 
        TO DB, THESE ARE FOR USE WITH VALIDATION -->
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.7.Final</version>
        <exclusions>
            <exclusion>
                <artifactId>validation-api</artifactId>
                <groupId>javax.validation</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator-annotation-processor -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>6.0.7.Final</version>
                    <exclusions>
            <exclusion>
                <artifactId>validation-api</artifactId>
                <groupId>javax.validation</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-cdi</artifactId>
        <version>6.0.7.Final</version>
                    <exclusions>
            <exclusion>
                <artifactId>validation-api</artifactId>
                <groupId>javax.validation</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.0.Final</version>
    </dependency>       
    <!-- ********************************************************************************************************** -->
    <!-- API and reference implementation of expression language {a.b} in html 
        code -->
    <!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.glassfish.web/javax.el -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>javax.el</artifactId>
        <version>2.2.6</version>
    </dependency>
</dependencies>

解决方案

The situation is provoked by having javaee-web-api 7.0 as dependency:

<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-web-api</artifactId>
  <version>7.0</version>
  <scope>provided</scope>
</dependency>

This dependency provided by your servlet or application container at runtime is giving you an older api for javax.validation.

You have two things to try:

Change the version of javaee-web-api to 8.0

This is the fastest solution if you are deploying your web app to a servlet or application container that supports Java EE 8.0 (for example: it seems to work in Tomcat 8.5.X but reading the documentation, only Tomcat 9 provides support for Java EE 8).

Keep javaee-web-api as 7.0 and downgrade hibernate-validator, validation-api dependencies:

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

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

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator-annotation-processor</artifactId>
  <version>5.4.2.Final</version>
</dependency>    

You have to change also some imports such as @Email or @NotEmpty from javax.validation package to org.hibernate.validator.constraints (those annotations are Deprecated in 6.0.X hibernate-validator versions because they're included inside javax.validation api).

这篇关于Maven使用错误版本的javax.validation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆