简体   繁体   English

无法在Springboot Gradle项目中解析@Entity和javax.persistence.Entity

[英]Cannot resolve @Entity and javax.persistence.Entity in Springboot Gradle project

I am following the guide on https://spring.io/guides/gs/accessing-data-mysql/ to start using MySQL for Gradle project, however, when I try to add in @Entity annotation it all 我正在按照https://spring.io/guides/gs/accessing-data-mysql/上的指南开始使用MySQL for Gradle项目,但是,当我尝试在@Entity注释中添加所有内容时

在此处输入图片说明

Here is my build.gradle, which follows the same thing on the website: 这是我的build.gradle,它在网站上遵循相同的内容:

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
    baseName = 'gs-accessing-data-mysql'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")

    // JPA Data (We are going to use Repositories, Entities, Hibernate, etc...)
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'

    // Use MySQL Connector-J
    compile 'mysql:mysql-connector-java'

    testCompile('org.springframework.boot:spring-boot-starter-test')
}

Remove compile group: 'javax.persistence', name: 'persistence-api', version: '1.0' and try below after this as jar might be corrupted. 删除compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'然后尝试以下操作,因为jar可能已损坏。

  1. Run ./gradlew clean install then check.. 运行./gradlew clean install然后检查。

  2. if above not work: then delete ~/.gradle/caches and again run gradle install command to re-import all dependencies. 如果以上方法不起作用:则delete ~/.gradle/caches然后再次运行gradle install命令以重新导入所有依赖项。

  3. Restart IDE and again import project. 重新启动IDE,然后再次导入项目。

As you can seee in dependency tree of SpringBoot, javax.persistence is already included in spring-boot-starter-data-jpa and it's not 1.0 . 如您所见,在SpringBoot的依赖树中, javax.persistence已经包含在spring-boot-starter-data-jpa ,并且不是1.0

在此处输入图片说明

Remove: 去掉:

compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate 未知实体(不缺少 @Entity 或导入 javax.persistence.Entity ) - Hibernate unknown entity (not missing @Entity or import javax.persistence.Entity ) Hibernate Eclipse未知实体(使用javax.persistence.Entity) - Hibernate Eclipse Unknown Entity (using javax.persistence.Entity) java.lang.ClassNotFoundException:javax.persistence.Entity - java.lang.ClassNotFoundException: javax.persistence.Entity JPA impementor是否实现javax.persistence.Entity批注? - Do JPA impementor implement javax.persistence.Entity annotation? "Lombok + QueryDsl + Mapstruct:错误编译:java.lang.NoClassDefFoundError:javax\/persistence\/Entity:javax.persistence.Entity" - Lombok + QueryDsl + Mapstruct: error compiling: java.lang.NoClassDefFoundError: javax/persistence/Entity: javax.persistence.Entity 休眠映射异常,尽管我导入导入javax.persistence.Entity - hibernate mapping exception though i import import javax.persistence.Entity 即使存在jar,Eclipse也无法找到javax.persistence.Entity - Eclipse can't find javax.persistence.Entity even though jar is present javax.persistence.NoResultException: 未找到要查询的实体 - javax.persistence.NoResultException: No entity found for query 上下文初始化失败。 找不到文件[javax / persistence / Entity.class],因为它不存在,所以无法打开 - Context initialization failed. File not found [javax/persistence/Entity.class] cannot be opened because it does not exist javax.persistence.EntityNotFoundException:无法找到具有 id 的实体 - javax.persistence.EntityNotFoundException: Unable to find entity with id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM