在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://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 集成。
关于java - org.springframework.data.mongodb.core.mapping.Document无法引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61746668/