我正在遵循 https://spring.io/guides/gs/accessing-data-mysql/ 上的指南然而,当我尝试添加 @Entity 注释时,开始将 MySQL 用于 Gradle 项目
这是我的 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 可能已损坏。
运行
./gradlew clean install
然后检查..如果上述不起作用:则
删除 ~/.gradle/caches
并再次运行 gradle install 命令以重新导入所有依赖项。重新启动 IDE 并再次导入项目。
关于java - 无法解析 Springboot Gradle 项目中的 @Entity 和 javax.persistence.Entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52734826/