Java org.springframework.beans.factory.unsatifiedDependencyException:创建名为';solrDocumentController';
我将按照以下步骤创建一个spring应用程序 这是我的主课Java org.springframework.beans.factory.unsatifiedDependencyException:创建名为';solrDocumentController';,java,spring,spring-boot,solr,Java,Spring,Spring Boot,Solr,我将按照以下步骤创建一个spring应用程序 这是我的主课 package com.example.webtool; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.solr.repository.config.EnableSolrRepos
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.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);
}
}
我的应用程序有什么问题?错误日志告诉您: 未找到com.example.webtool.model.Document类所需的标识符属性代码>
@Id
@索引(name=“id”,type=“string”)
私有字符串id;
错误日志告诉您:
未找到com.example.webtool.model.Document类所需的标识符属性代码>
@Id
@索引(name=“id”,type=“string”)
私有字符串id;
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]