【问题标题】:Does Spring Data Solr work with zookeeper host?Spring Data Solr 是否与 zookeeper 主机一起使用?
【发布时间】:2018-11-15 03:30:00
【问题描述】:

我有一个 Spring Boot 应用程序,并且在我的属性文件中有:

spring.data.solr.host=http://{SOLR.HOST}/solr

这可以正常工作,但是如果我将 SOLR.HOST 替换为 ZOOKEEPER.HOST,它会在与服务器通信时引发 I/O 异常。在我看来,spring data 是试图通过 http 请求直接访问 zookeeper 端点,而 zookeeper 不处理 http 请求?如果是这样,我该怎么做才能让 spring 数据与 zookeeper 一起使用?

【问题讨论】:

    标签: spring solr apache-zookeeper spring-data-solr


    【解决方案1】:

    看来您需要使用 CloudSolrClient 来实例化 SolrClient bean https://dzone.com/articles/spring-data-solr-cloud-zookeeper-mongodb-ubuntu-in

    @Configuration
    @EnableSolrRepositories(basePackages = { "ca.knc.restaurant.repository.solr" }, multicoreSupport = true)
    public class SpringSolrConfig {
        @Value("${spring.data.solr.zk-host}")
        private String zkHost;
        @Bean
        public SolrClient solrClient() {
            return new CloudSolrClient(zkHost);
        }
        @Bean
        public SolrTemplate solrTemplate(SolrClient solrClient) throws Exception {
            return new SolrTemplate(solrClient);
        }
    }
    

    你也可以通过application.properties设置,让Spring Boot自动配置:

    spring.data.solr.zk-host= #ZooKeeper主机地址形式 主机:端口。

    https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

    https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java


    否则,您可以使用 LoadBalancer 为您的 Solr 实例提供服务并使用常规 Solr 主机配置

    例如,我有以下配置(yml config):

    spring.data.solr.host: https://foo.bar.com/solr
    

    其中 foo.bar.com 使用 Apache 作为标准负载均衡器为我的 Solr 实例之一提供服务。

    【讨论】:

    • 我不知道spring.data.solr.zk-host。谢谢,+1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 2021-07-08
    相关资源
    最近更新 更多