[英]Error when adding “spring-boot-starter-data-jpa” dependency to Spring project
[英]Spring boot not adding spring-boot-starter-data-jpa
當試圖通過gradle將spring-boot-starter-data-jpa添加到我的項目時,它就是不這樣做。 @Entity 標簽不起作用,並且 jar 沒有出現在項目和外部依賴項文件夾中。 除非我放入@Entity 標記,否則不會出現錯誤。 這是我的 gradle 文件供參考。
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.Hype'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:
'2.3.4.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.session:spring-session-jdbc'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
在有人提到它之前,是的,我已經嘗試多次清理和重建項目。
如果您使用的是 Gradle 6.x, compile
配置已被棄用。 自 Gradle 3.4 以來,不鼓勵使用它。 您應該改用implementation
。 此更改還會使此依賴項與構建腳本中的其他依賴項更加一致。 您可以在Gradle 文檔中了解更多相關信息。
您還指定了spring-boot-starter-data-jpa
依賴項的版本。 這不是必需的,因為版本可以由您應用的 Spring 啟動插件的版本確定。 這就是腳本中未聲明版本的其他依賴項所發生的情況。 它使所有版本保持同步變得更加容易。
簡而言之,嘗試將依賴聲明更新為如下所示:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
已解決:問題出在 Spring 工具套件中,使用 Project->Clean 不會更新 gradle 依賴項。 必須右鍵單擊 build.gradle->gradle->refresh gradle 項目才能更新所有內容。
按照之前的建議,在 VS Code cleaning Java 項目中幫我解決了這個問題:打開“Java Project”視圖 -> “...” -> “Clean Workspace”
根據 VS Code 配置,清理后,gradle 會自動重建依賴項。 如果沒有,可以右擊build.gradle和select“更新項目”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.