java - org.springframework.data.mongodb.core.mapping.Document无法引用

标签 java spring eclipse gradle spring-data-jpa

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

错误 enter image description here

如何解决?

最佳答案

// 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/

相关文章:

java - 将 POJO 上传到 JPA 实体类

java.security.AccessControlException : access denied (java. io.FilePermission

java - 附加到先前输出的 JSP 错误页面

java - Spring 应用程序上的最大 session 数,而不是应用程序上用户的最大 session 数

java - 无法在Java Applet中实现play方法,JMF安装不正确

java - 未经检查的转换警告

Java 8 读取文件列表,但文件保持打开状态,直到服务器卡住

java - 如何使用 Spring Boot SPEL 以编程方式读取/解析 yaml 值?

c++ - 连续使用 std::list 导致崩溃

java - 组织.apache.jasper.JasperException : Could not add one or more tag libraries