[英]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可能已损坏。
Run ./gradlew clean install
then check.. 运行./gradlew clean install
然后检查。
if above not work: then delete ~/.gradle/caches
and again run gradle install command to re-import all dependencies. 如果以上方法不起作用:则delete ~/.gradle/caches
然后再次运行gradle install命令以重新导入所有依赖项。
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.