簡體   English   中英

Spring Data Solr 3.0.6版本的基於Java的配置

[英]java based configuration for Spring data solr 3.0.6 release

我正在嘗試使用基於Java的配置在Spring Boot中使用Spring Solr Starter。 我已經閱讀了官方文檔https://docs.spring.io/spring-data/solr/docs/current/reference/html/#solr.annotation ,只有一個示例使用以下代碼連接EmbeddedSolrServerFactory:

@Configuration
@EnableSolrRepositories(
    basePackages = "com.tutorial.demo.repositories"
)
@ComponentScan
public class ApplicationConfig {
    @Bean
    public SolrClient solrClient() throws Exception {
         EmbeddedSolrServerFactory factory = new 
         EmbeddedSolrServerFactory("classpath:com/acme/solr");
         return factory.getSolrServer();
    }

    @Bean
    public SolrOperations solrTemplate() throws Exception {
    return new SolrTemplate(solrClient());
   }}

誰能幫助我如何通過在Spring Data Solr中使用基於Java的配置來連接到我的Solr服務器(不是嵌入式服務器)。 提前致謝。

@Configuration
@EnableSolrRepositories(
    basePackages = "path for your solr repository package"
)
@ComponentScan
public class ApplicationConfig {
private final SolrPropertyConfig solrPropertyConfig;

public ApplicationConfig(SolrPropertyConfig solrPropertyConfig) {
    this.solrPropertyConfig = solrPropertyConfig;
}

@Bean
public SolrClient solrClient() throws Exception {
    return new HttpSolrClient.Builder(solrPropertyConfig.getSolrHost()).build();
}

@Bean
public SolrOperations solrTemplate() throws Exception {
    return new SolrTemplate(solrClient());
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM