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

这是我的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')
}发布于 2018-10-10 17:51:07
删除compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'并在此之后重试,因为jar可能已损坏。
./gradlew clean install,然后检查..delete ~/.gradle/caches,然后再次运行gradle install命令以重新导入所有dependencies.,然后再次导入项目。
发布于 2018-10-10 15:46:15
正如您在SpringBoot的依赖关系树中看到的,javax.persistence已经包含在spring-boot-starter-data-jpa中,并且它不是1.0。

删除:
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
https://stackoverflow.com/questions/52734826
复制相似问题