Java Spring如何设置多核Solr配置

时间:2016-06-08 08:34:14

标签: java spring solr

基本上我复制粘贴来自http://docs.spring.io/spring-data/solr/docs/1.0.x/reference/html/solr.repositories.html的多核配置,然后稍微调整一下,但它不起作用,因为我需要将corename-SolrClient添加到ClientFactory。但我是否只是创造了SolrCLient?我希望这一切能够与我机器上服务器上运行的核心相匹配。这是solr的配置类:

private static final String PROPERTY_NAME_SOLR_SERVER_URL = "solr.host";


      @Resource
      private Environment environment;

      @Bean
      public SolrClientFactory solrClientFactory() {
          MulticoreSolrClientFactory factory =  new MulticoreSolrClientFactory(
                  new HttpSolrClient(environment.getRequiredProperty(
                          PROPERTY_NAME_SOLR_SERVER_URL) ));
          return factory;
      }

      @Bean (name = "SolrTemplateMap")
      public Map<Language, SolrTemplate> solrTemplateList(){
          HashMap<Language, SolrTemplate> map = new HashMap<>();
          for (Language l : Language.values()){
              SolrTemplate template = new SolrTemplate (solrClientFactory());
              template.setSolrCore(l.toString());
              map.put( l, template);
          }
          return map;
      }

我尝试添加

for (Language l : Language.values()){
              factory.addSolrClientForCore(new HttpSolrClient(url + "/solr/" + l.toString()), l.toString());
          }

在工厂bean中,但它没有解决任何问题。 Language是一个枚举。

1 个答案:

答案 0 :(得分:2)

迟到的回复,不确定这是否会让你受益,但我希望它至少对某人有帮助。这样的事让我工作。

  @Bean (name = "SolrTemplateMap")
  public Map<Language, SolrTemplate> solrTemplateList(){
      HashMap<Language, SolrTemplate> map = new HashMap<>();
      for (Language l : Language.values()){
          SolrTemplate template = new SolrTemplate (configureHttpSolrServer(l));
          map.put( l, template);
      }
      return map;
  }

private SolrServer configureHttpSolrServer(String baseURL) {
        HttpSolrServerFactoryBean factoryBean = new HttpSolrServerFactoryBean();
        factoryBean.setUrl(baseURL);
        factoryBean.setMaxConnections(100);
        return factoryBean;
}