当前位置: 首页 > 知识库问答 >
问题:

初始化SolrRepository时出错:通过字段表示得依赖项不满足

彭嘉赐
2023-03-14
@SpringBootApplication
@ComponentScan(basePackages = { "com.ns.services.search", "com.ns.services.commons.exceptions" })
@EnableSolrRepositories(value = "com.ns.services.search", schemaCreationSupport = true, multicoreSupport =     true)
@EnableSwagger2
public class SearchServiceApplication {

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

    @Bean
    public HttpSolrClient solrClient() {
        return new HttpSolrClient("http://localhost:8983/solr");
    }

    @Bean
    public SolrTemplate solrTemplate(SolrClient client) throws Exception {
        return new SolrTemplate(client);
    }

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()).build();
    }

    @Bean
    public SolrTemplate bookTemplate() throws Exception {
        SolrTemplate solrTemplate = new SolrTemplate(solrClient());
        solrTemplate.setSolrCore("demo");
        return solrTemplate;
    }

}
@NoRepositoryBean
public interface BookRepository extends SolrCrudRepository<Book, String> {

    List<Book> findByName(String name);

}
public interface BookService {

    Book addBookToIndex(Book book);

}
@Service
public class BookServiceImpl implements BookService {

    public BookServiceImpl() {
        super();
    }

    @Autowired
    public BookRepository bookRepository;

    @Override
    public Book addBookToIndex(Book book) {
        return bookRepository.save(book);
    }

}

尝试启动服务时的异常跟踪:

2016-07-03 15:08:34.596信息35332---

共有1个答案

拓拔弘亮
2023-03-14

stacktrace包含

没有[com.neighbourspoon.services.search.repositories.bookrepository]类型的合格bean

这是因为BookRepository中的@norepositorybean注释。你应该移除它。这仅用于自定义中间存储库。在这里,您直接扩展了Spring数据存储库。

 类似资料: