2017-05-17 25 views
0

내 Solr 5.5.0 임베디드 서버 환경에 다른 코어를 추가하고 싶습니다. "제 세계에서"저는 임베디드 서버를 만들고 스프링 데이터가 핵심 구성을로드하도록합니다. 그러나 내 솔루션으로 모든 데이터가 기본 코어 "collection1"로 이동하는 것 같습니다. 지금까지 저는 스프링 부트 옆에있는 예제를 찾을 수 없었습니다. 하지만 그건 옵션이 아닙니다.원시 스프링 데이터 솔로로 임베디드 솔라에서 다중 코어를 구성하는 방법

내 구성은 지금까지 다음과 같습니다

여기
@Import({ 
    AppctxSolrEmbedded.class, 
    AppctxSolrHttp.class 
}) 
@EnableSolrRepositories(value = "de.my.application.*.repository", multicoreSupport = true) 
@Configuration 
public class AppctxSolr { 

    public @Bean SolrTemplate solrTemplate(
      @Named("solrClient") SolrClient solrClient) { 
     return new SolrTemplate(solrClient, "collection1"); 
    } 

    public @Bean SolrTemplate operatorSolrTemplate(
      @Named("solrClient") SolrClient solrClient) { 
     return new SolrTemplate(solrClient, "operator1"); 
    } 
} 

@Dev @Qual @RemoteDev 
@Configuration 
public class AppctxSolrEmbedded { 

    @Bean 
    public EmbeddedSolrServerFactoryBean solrClient(
      @Value("${solr.server}") String solrHome) { 
     EmbeddedSolrServerFactoryBean factory = new EmbeddedSolrServerFactoryBean(); 
     factory.setSolrHome(solrHome); 
     return factory; 
    } 
} 

@Prod 
@Configuration 
public class AppctxSolrHttp { 

    @Bean 
    public HttpSolrClientFactoryBean solrClient(
      @Value("${solr.server}") String baseURL) { 
     HttpSolrClientFactoryBean factory = new HttpSolrClientFactoryBean(); 
     factory.setUrl(baseURL); 
     return factory; 
    } 
} 

답변

2

내가 그것을

@Configuration 
@EnableSolrRepositories(multicoreSupport = true) 
public class MulticoreSolrConfiguration { 

    @Autowired 
    private SolrClient solrClient; 

    @Bean 
    public SolrOperations solrTemplate() throws ParserConfigurationException, SAXException, IOException { 
    return new SolrTemplate(this.solrClient); 
    } 

    @Bean 
    public MulticoreSolrClientFactory multicoreSolrClientFactory() 
     throws ParserConfigurationException, SAXException, IOException { 
    return new MulticoreSolrClientFactory(this.solrClient, "operator1", "collection1"); 
    } 

    @Bean(name = "operatorSolrClient") 
    public SolrClient operatorSolrClient() throws IOException, SAXException, ParserConfigurationException { 
    return this.multicoreSolrClientFactory().getSolrClient("operator1"); 
    } 

    @Bean(name = "operatorSolrTemplate") 
    public SolrTemplate operatorSolrTemplate() throws IOException, SAXException, ParserConfigurationException { 
    return new SolrTemplate(this.operatorSolrClient()); 
    } 
} 

    @Bean(name = "collectionSolrClient") 
    public SolrClient collectionSolrClient() throws IOException, SAXException, ParserConfigurationException { 
    return this.multicoreSolrClientFactory().getSolrClient("collection1"); 
    } 

    @Bean(name = "collectionSolrTemplate") 
    public SolrTemplate collectionSolrTemplate() throws IOException, SAXException, ParserConfigurationException { 
    return new SolrTemplate(this.collectionSolrClient()); 
    } 
} 

할 것입니다 그리고 대신 AppctxSolrEmbedded 및 AppctxSolrHttp, 당신이

처럼 뭔가를 할 수있는 방법입니다
@Configuration 
class SolrConfiguration { 

    private final SolrProperties solrProperties; // Has details about solr host, port, directory ..... 

    @Autowired 
    public SolrConfiguration(final SolrProperties solrProperties) { 
    this.solrProperties = solrProperties; 
    } 

    @Bean 
    SolrClient solrClient() { 
    final SolrClient solrClient; 
    if (this.solrProperties.isEmbedded()) { 
     solrClient = createEmbeddedSolrClient(); 
    } else { 
     solrClient = createStandaloneSolrClient(); 
    } 

    return solrClient; 
    } 

    private SolrClient createEmbeddedSolrClient() { 
    final String solrConfigurationFolder = this.solrProperties.getSolr().getHome(); 

    final EmbeddedSolrServerFactoryBean factoryBean = new EmbeddedSolrServerFactoryBean(); 
    factoryBean.setSolrHome(solrConfigurationFolder); 

    return factoryBean.getSolrClient(); 
    } 

    private SolrClient createStandaloneSolrClient() { 
    final String solrUrl = this.solrProperties.getHost(); 

    return new HttpSolrClient(solrUrl); 
    } 
} 

당신이 볼 수 있듯이, embeddedsolrclient 또는 standaloneclient를 기반으로 속성 집합. 프로필 (Autowire 환경 및 프로필 확인)에 따라 수행하도록 변경할 수 있습니다.

+0

감사합니다. 내 문제가 해결되었습니다. –