org.springframework.beans.factory.UnsatisfiedDependencyException: ошибка создания компонента с именем 'solrDocumentController' - PullRequest
0 голосов
/ 30 мая 2019

Я создаю приложение Spring, следуя этому учебнику

Вот мой основной класс

package com.example.webtool;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.solr.repository.config.EnableSolrRepositories;


@SpringBootApplication
@EnableSolrRepositories(
        basePackages = "com.example.webtool.repository"
)
public class WebtoolApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebtoolApplication.class, args);
    }

}

Это мой класс репозитория

package com.example.webtool.repository;

import java.util.List;
import org.springframework.data.solr.repository.SolrCrudRepository;
import com.example.webtool.model.Document;
import org.springframework.stereotype.Service;

public interface DocumentRepository extends SolrCrudRepository<Document, String> {
    List<Document> findAllByPerson(String person); // find documents whose person name matches the name of the person in the query
    List<Document> findAllByRank(String rank); // find documents whose rank matches the rank of the person in the query

}

Это мой класс документов

package com.example.webtool.model;

import org.apache.solr.client.solrj.beans.Field;
import org.springframework.data.solr.core.mapping.SolrDocument;

@SolrDocument(solrCoreName = "gettingstarted")
public class Document {

    @Field
    private String person;

    @Field
    private String rank;

    @Field
    private String text;

    public Document() { }

    public Document(String person, String rank, String text) {
        this.person = person;
        this.rank = rank;
        this.text = text;

    }

    public String getPerson() {
        return person;
    }

    public void setPerson(String person) {
        this.person = person;
    }

    public String getRank() {
        return rank;
    }

    public void setRank(String rank) {
        this.rank = rank;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

}

И это мой класс контроллеров

package com.example.webtool.controller;

import com.example.webtool.model.Document;
import com.example.webtool.repository.DocumentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Siddharth Sinha
 */

@RestController
public class SolrDocumentController {

    @Autowired
    private DocumentRepository documentRepository;

    @RequestMapping("/")
    public String SampleController() {
        return "THis is a sample page!!!!";
    }

    @PostMapping("/search")
    public List<Document> getDocs(@RequestBody String name) {
        return this.documentRepository.findAllByPerson(name);
    }
}

Когда я пытаюсь создать приложение, я получаю исключение, которое выглядит следующим образом:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'solrDocumentController': Unsatisfied dependency expressed through field 'documentRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'documentRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.solr.repository.support.SimpleSolrRepository]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Required identifier property not found for class com.example.webtool.model.Document!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]

Что не так с моим приложением?

1 Ответ

2 голосов
/ 30 мая 2019

Журнал ошибок сказал вам:

Required identifier property not found for class com.example.webtool.model.Document!

@Id
@Indexed(name = "id", type = "string")
private String id;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...