Maven using wrong version of javax.validation

前端 未结 5 1288
眼角桃花
眼角桃花 2020-12-20 22:59

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 databas

相关标签:
5条回答
  • 2020-12-20 23:20

    Do mvn dependency:tree , May you have another dependencies that use hibernate-annotations, and conflict with your spring version, also you can find them and exclude from class path, as below:

     <exclusions>
        <exclusion>
           <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
        </exclusion>
      </exclusions>
    

    I hopefully help you.

    0 讨论(0)
  • 2020-12-20 23:28

    Had the same issue as jekho, but solved it with:

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-referencing</artifactId>
        <version>22.3</version>
        <exclusions>
            <exclusion>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    

    I found which dependency was using javaee-api by using maven's dependency:tree on my project which points out which packages are being used by which dependency.

    0 讨论(0)
  • 2020-12-20 23:32

    Try adding this dependency to your pom.xml

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.1.Final</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-20 23:33

    Had the same problem with Springboot 2.1.4.RELEASE and some GeoTools dependencies.

    Validation-api was specified from javax.validation and javaee-api jars.

    Put them as dependencies like following:

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
    </dependency>
    
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    
    0 讨论(0)
  • 2020-12-20 23:44

    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).

    0 讨论(0)
提交回复
热议问题