2016-06-08 66 views
0

基本上我复制粘贴从http://docs.spring.io/spring-data/solr/docs/1.0.x/reference/html/solr.repositories.html多核配置,然后调整了一下,但它不起作用,因为我需要将corename-SolrClient添加到ClientFactory。但是,我是否仅仅是创造了SolrCLient?我希望它能匹配我机器上服务器上运行的核心。这是Solr的配置类:Java Spring如何设置多核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; 
     } 

我试图在工厂bean添加

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

,但它并没有解决任何问题。 Language是一个枚举。

回答

1

最近的回复,不知道这是否会对您有益,但我希望它至少对别人有帮助。像这样的东西让我工作。

@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; 
}