How to find correct jar file of Spring Data JPA an

2019-07-31 20:12发布

问题:

I'm using Spring MVC and Spring Data JPA and facing with an exception of jar version.

This is my pom:

<properties>
    <spring.version>4.2.4.RELEASE</spring.version>
    <hibernate.version>4.3.8.Final</hibernate.version>
    <mysql.version>5.1.10</mysql.version>
    <junit-version>4.11</junit-version>
    <servlet-api-version>3.1.0</servlet-api-version>
    <spring-security-version>4.0.4.RELEASE</spring-security-version> 
    <spring-data-solr.verion>1.2.0.RELEASE</spring-data-solr.verion>         
    <springbatch.version>3.0.6.RELEASE</springbatch.version>
    <jsp-version>2.1</jsp-version>
    <jstl-version>1.2</jstl-version>
    <java.version>1.7</java.version>
    <liquibase.version>3.1.1</liquibase.version>
    <spring.data.jpa.version>1.10.3.RELEASE</spring.data.jpa.version>   
    <spring.social.version>1.1.0.RELEASE</spring.social.version>                        
</properties>

This is my class:

import org.springframework.data.jpa.repository.JpaRepository;
public interface RoleRepository extends JpaRepository<Role, Long> {

}

I received an error warning on Eclipse with message:

The type org.springframework.data.repository.query.QueryByExampleExecutor cannot be resolved. It is indirectly referenced from required .class files

It seem my Spring data jpa jar version is incorrect, but I don't know find correct version. My Spring verion: 4.2.4.RELEASE is latest

How to fix this error? Thank so much !

回答1:

Since you have a POM, it means you're using Maven, and Maven has a plugin called dependency on which you can call dependency:list that will list all your jar dependencies together with their versions.

Just call at the root of your project (given that you're using a starter):

./mvnw dependency:list

and you will list your jars:

[INFO] ------------------------------------------------------------------------
[INFO] Building XXXXXXX 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.10:list (default-cli) @ xxxxxxx ---
[INFO] 
[INFO] The following files have been resolved:
[INFO]    org.apache.lucene:lucene-backward-codecs:jar:5.5.2:compile
[INFO]    org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.1.RELEASE:compile

You can also use dependency:analyze-duplicate, dependency:tree or dependency:analyze-report to check everything is declared once. Check the documentation for this plugin, it is really useful when you're facing dependencies issues.

Here's a sample of dependency:tree:

[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ ouaknine ---
[INFO] com.rdlopes.ouaknine:ouaknine:war:0.0.2-SNAPSHOT
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-hibernate5:jar:2.8.6:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.6:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.8.6:compile
[INFO] |  \- javax.transaction:jta:jar:1.1:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-hppc:jar:2.8.6:compile
[INFO] |  \- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-json-org:jar:2.8.6:compile
[INFO] |  \- org.apache.geronimo.bundles:json:jar:20090211_1:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.8.6:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] +- com.h2database:h2:jar:1.4.193:compile
[INFO] +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] |  +- net.minidev:json-smart:jar:2.2.1:test
[INFO] |  |  \- net.minidev:accessors-smart:jar:1.1:test
[INFO] |  |     \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.22:compile
[INFO] +- com.jcraft:jzlib:jar:1.1.3:compile
[INFO] +- com.mattbertolini:liquibase-slf4j:jar:2.0.0:compile
[INFO] +- com.ryantenney.metrics:metrics-spring:jar:3.1.3:compile
[INFO] |  +- io.dropwizard.metrics:metrics-healthchecks:jar:3.1.2:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.3.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-aop:jar:4.3.6.RELEASE:compile
[INFO] +- com.zaxxer:HikariCP:jar:2.6.0:compile
[INFO] +- commons-io:commons-io:jar:2.5:compile
[INFO] +- io.dropwizard.metrics:metrics-annotation:jar:3.1.2:compile
[INFO] +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] +- io.dropwizard.metrics:metrics-json:jar:3.1.2:compile

On my MacBook Pro, I simply call in the Terminal:

macbook-pro-de-rui:ouaknine rui$ ./mvnw dependency:list | grep jpa
[INFO]    org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO]    org.springframework.data:spring-data-jpa:jar:1.11.0.RELEASE:compile
[INFO]    org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.1.RELEASE:compile


回答2:

The place to go to find the version compatibility is https://www.mvnrepository.com/ You put in your version and it will show the associated libs and their versions. Cool site. It will even show you how to enter your POM. For your spring data jpa, I entered "Spring data jpa" in the search, clicked on the library, then clicked on your version "1.10.3". If you scroll to the bottom, it will show the associated compile dependencies and their versions.