java - org.springframework.data.mongodb.core.mapping.Document 无法引用
问题描述
在build.gradle
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id 'eclipse'
id 'java-library'
}
group = 'io.sample'
version = '3.0.0-SNAPSHOT'
sourceCompatibility = '14'
targetCompatibility = '14'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenLocal()
mavenCentral()
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
// implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
package com.mastering.spring.reactive.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document
public class Stock {
private String code;
private String name;
private String description;
public Stock() {
}
public Stock(String code, String name, String description) {
this.name = name;
this.code = code;
this.description = description;
}
@Id
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Stock person = (Stock) o;
if (name != null ? !name.equals(person.name) : person.name != null) {
return false;
}
if (code != null ? !code.equals(person.code) : person.code != null) {
return false;
}
return description != null ? description.equals(person.description) : person.description == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (code != null ? code.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Person{" + "id='" + name + '\'' + ", firstname='" + code + '\'' + ", lastname='" + description + '\''
+ '}';
}
}
我从https://github.com/PacktPublishing/Working-with-Data-and-Cloud-in-Spring-5.0/blob/master/Section%204/src/main/java/com/mastering/spring/reactive复制/model/Stock.java
如何解决?
解决方案
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
... 取决于org.springframework.data:spring-data-mongodb
,因此应该知道该类。尝试下载依赖项:./gradlew build --refresh-dependencies
. 默认build.gradle
条目较少;IDEA可能有更好的 Gradle 集成。
推荐阅读
- angular - 如何在Angular中的异步函数之后运行另一个函数
- python-3.x - Python3.6/3.7 中 SSL 证书验证失败
- javascript - 无法在 React 中的 json 中映射数组
- django - 保存 django 表单时添加附加数据
- c# - 处理来自 Azure Blob 存储批处理操作的看似未记录的错误代码:TlsVersionNotPermitted
- sharepoint - 在 SharePoint 日历中,如何为其他语言的下一个和上一个按钮添加替代文本?
- c# - 我应该在设置之前检查 VisualElement.IsVisible 吗?
- java - Apache Flink:未应用环境并行设置
- python - Django - 产品页面中未显示的项目
- javascript - 仅在打开 Modal 时如何在 React Modal 中触发 API?