基于java的Spring数据solr 3.0.6发布版

时间:2018-04-14 11:46:44

标签: java spring spring-boot solr spring-data-solr

我正在尝试使用基于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服务器(不是嵌入式服务器)。提前谢谢。

1 个答案:

答案 0 :(得分:1)

@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());
}
}
相关问题