如何为多个内核配置带有存储库的Spring Data Solr

编程入门 行业动态 更新时间:2024-10-19 02:23:23
本文介绍了如何为多个内核配置带有存储库的Spring Data Solr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有使用带有多核支持的存储库的solr设置spring数据的详细而完整的解释?

Is there a detailed and complete explanation for setting up spring data with solr using repositories with multicore support?

推荐答案

唯一需要用于spring-data-solr的依赖项是

The only dependency that need to be used for spring-data-solr is

<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.5.2.RELEASE</version> </dependency>

它会下载solrj依赖项,并且绝不能用更高版本的solrj覆盖. 同样,我们最好使用HttpSolrServer而不是EmbeddedSolrServer.

It downloads solrj dependency and this must not be overridden with later versions of solrj. Also It is always preferable to use HttpSolrServer over EmbeddedSolrServer which is what we will be working with.

Configuration类应如下所示:

The Configuration class should look like this:

@Configuration @EnableSolrRepositories(value = "com.package.",multicoreSupport = true) public class SolrConfig { @Bean public SolrServer solrServer() throws Exception { HttpSolrServerFactoryBean f = new HttpSolrServerFactoryBean(); f.setUrl("localhost:8983/solr"); f.afterPropertiesSet(); return f.getSolrServer(); } @Bean public SolrTemplate solrTemplate(SolrServer solrServer) throws Exception { return new SolrTemplate(solrServer()); } }

文档实体应包含有关它们属于哪个核心的信息

The document entity should contain information about which core they belong to

@SolrDocument(solrCoreName = "core1") public class Document1 { @Id @Field private String id; /**other attributes**/ }

另一个文件应该是

@SolrDocument(solrCoreName = "core2") public class Document2 { @Id @Field private String id; /**other attributes**/ }

现在最好的部分是您已经完成.只需以简单的旧方法设置存储库就可以了

Now the best part is you are already done. Simply setting up repository in the plain old way does the trick

public interface SolrCore1Repository extends SolrCrudRepository<Document1,String> { // optional code }

另一个仓库就像

public interface SolrCore2Repository extends SolrCrudRepository<Document2,String> { // optional code }

一旦solr在指定的url上运行,并且其中包含根据pojo设置的字段,就完成了.

Once solr is running on the url specified and it has fields according to the pojo, you are done.

更多推荐

如何为多个内核配置带有存储库的Spring Data Solr

本文发布于:2023-11-28 15:23:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642943.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   内核   何为   Solr   Data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!