java - 无法解析 Springboot Gradle 项目中的 @Entity 和 javax.persistence.Entity

标签 java mysql spring spring-boot gradle

我正在遵循 https://spring.io/guides/gs/accessing-data-mysql/ 上的指南然而,当我尝试添加 @Entity 注释时,开始将 MySQL 用于 Gradle 项目

enter image description here

这是我的 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')
}

最佳答案

删除编译组:'javax.persistence',名称:'persistence-api',版本:'1.0'并在此之后尝试以下操作,因为 jar 可能已损坏。

  1. 运行./gradlew clean install然后检查..

  2. 如果上述不起作用:则删除 ~/.gradle/caches 并再次运行 gradle install 命令以重新导入所有依赖项。

  3. 重新启动 IDE 并再次导入项目。

关于java - 无法解析 Springboot Gradle 项目中的 @Entity 和 javax.persistence.Entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52734826/

相关文章:

java - Selenium 页面对象重用

java - 如何知道哪个插件正在Gradle中添加 “run”任务

PHP Mysql - 图像未在浏览器上显示(图像损坏)

MySQL Left Join - 如何获取第二张表中的记录数

java - Spring boot应用程序启动时如何缓存数据

spring - 测试 Spring 存储库

mysql - 在 spring 4 mvc 中根据客户端登录更改相同的服务器数据库

java - 泛型和问号

java - Raspberry Pi 2 Java - 无法加载主类/未找到类 WebView

mysql - 如何以 CSV 格式输出 MySQL 查询结果?