【问题标题】:javax.persistance.Entity not getting imported?javax.persistence.Entity 没有被导入?
【发布时间】:2017-08-10 20:19:45
【问题描述】:

我试图着手进行春季数据审计。所以我从下面写的一个简单的 build.gragle 开始。但我无法获得 javax.persistence 的所有类。* 我的意思是 @Entity 超过任何 POJO 给了我无法解析符号并且没有可用的导入。我无法弄清楚我缺少什么我的 gradle 文件。

buildscript {
    ext {
        springBootVersion = '1.5.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'


jar {
    baseName = 'auditTest'
    version =  '1.0.0-SNAPSHOT'
}

repositories {
    mavenCentral()
    mavenLocal()
}
group = 'com.shubham'
version = '1.0.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.data:spring-data-jpa:1.11.1.RELEASE')
}

但后来我从Spring's Getting Started with JPA 页面复制了 gradle 文件。 javax.persistance 的所有课程都可用。

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'Audit'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    testCompile("org.springframework.boot:spring-boot-starter-test")
}

那么我在build.gradle 文件中遗漏了什么?

【问题讨论】:

  • 似乎缺少指向 repo 的 url https://repository.jboss.org/nexus/content/repositories/releases。因此,没有下载 jar。
  • 我已尝试包含该网址。它没有工作

标签: java spring jpa gradle


【解决方案1】:

看gradle的依赖图(gradlew dependencies)

+--- org.springframework.boot:spring-boot-starter-data-jpa: -> 1.4.3.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.4.3.RELEASE (*)
|    +--- org.springframework.boot:spring-boot-starter-aop:1.4.3.RELEASE
|    |    +--- org.springframework.boot:spring-boot-starter:1.4.3.RELEASE (*)
|    |    +--- org.springframework:spring-aop:4.3.5.RELEASE (*)
|    |    \--- org.aspectj:aspectjweaver:1.8.9
|    +--- org.springframework.boot:spring-boot-starter-jdbc:1.4.3.RELEASE
|    |    +--- org.springframework.boot:spring-boot-starter:1.4.3.RELEASE (*)
|    |    +--- org.apache.tomcat:tomcat-jdbc:8.5.6
|    |    |    \--- org.apache.tomcat:tomcat-juli:8.5.6
|    |    \--- org.springframework:spring-jdbc:4.3.5.RELEASE
|    |         +--- org.springframework:spring-beans:4.3.5.RELEASE (*)
|    |         +--- org.springframework:spring-core:4.3.5.RELEASE
|    |         \--- org.springframework:spring-tx:4.3.5.RELEASE
|    |              +--- org.springframework:spring-beans:4.3.5.RELEASE (*)
|    |              \--- org.springframework:spring-core:4.3.5.RELEASE
|    +--- org.hibernate:hibernate-core:5.0.11.Final
|    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    +--- org.javassist:javassist:3.18.1-GA -> 3.20.0-GA
|    |    +--- antlr:antlr:2.7.7
|    |    +--- org.jboss:jandex:2.0.0.Final
|    |    +--- dom4j:dom4j:1.6.1
|    |    |    \--- xml-apis:xml-apis:1.0.b2 -> 1.4.01
|    |    \--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final
|    |         \--- org.jboss.logging:jboss-logging:3.3.0.Final
|    +--- org.hibernate:hibernate-entitymanager:5.0.11.Final
|    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final
|    |    +--- org.hibernate:hibernate-core:5.0.11.Final (*)
|    |    +--- dom4j:dom4j:1.6.1 (*)
|    |    +--- org.hibernate.common:hibernate-commons-annotations:5.0.1.Final (*)
|    |    +--- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
|    |    \--- org.javassist:javassist:3.18.1-GA -> 3.20.0-GA
|    +--- javax.transaction:javax.transaction-api:1.2
|    +--- org.springframework.data:spring-data-jpa:1.10.6.RELEASE
|    |    +--- org.springframework.data:spring-data-commons:1.12.6.RELEASE
|    |    |    +--- org.springframework:spring-core:4.2.9.RELEASE -> 4.3.5.RELEASE
|    |    |    +--- org.springframework:spring-beans:4.2.9.RELEASE -> 4.3.5.RELEASE (*)
|    |    |    +--- org.slf4j:slf4j-api:1.7.22
|    |    |    \--- org.slf4j:jcl-over-slf4j:1.7.22 (*)
|    |    +--- org.springframework:spring-orm:4.2.9.RELEASE -> 4.3.5.RELEASE
|    |    |    +--- org.springframework:spring-beans:4.3.5.RELEASE (*)
|    |    |    +--- org.springframework:spring-core:4.3.5.RELEASE
|    |    |    +--- org.springframework:spring-jdbc:4.3.5.RELEASE (*)
|    |    |    \--- org.springframework:spring-tx:4.3.5.RELEASE (*)
|    |    +--- org.springframework:spring-context:4.2.9.RELEASE -> 4.3.5.RELEASE (*)
|    |    +--- org.springframework:spring-aop:4.2.9.RELEASE -> 4.3.5.RELEASE (*)
|    |    +--- org.springframework:spring-tx:4.2.9.RELEASE -> 4.3.5.RELEASE (*)
|    |    +--- org.springframework:spring-beans:4.2.9.RELEASE -> 4.3.5.RELEASE (*)
|    |    +--- org.springframework:spring-core:4.2.9.RELEASE -> 4.3.5.RELEASE
|    |    +--- org.slf4j:slf4j-api:1.7.22
|    |    \--- org.slf4j:jcl-over-slf4j:1.7.22 (*)
|    \--- org.springframework:spring-aspects:4.3.5.RELEASE
|         \--- org.aspectj:aspectjweaver:1.8.9

我看到org.hibernate.javax.persistence:hibernate-jpa-2.1-api(javax.persistence.* 所在的位置)不依赖于org.springframework.data:spring-data-jpa。相反,它取决于org.hibernate:hibernate-coreorg.hibernate:hibernate-entitymanager

所以你也应该编译这些包或留在org.springframework.boot:spring-boot-starter-data-jpa

【讨论】:

    猜你喜欢
    • 2020-09-17
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    相关资源
    最近更新 更多