简体   繁体   中英

java based configuration for Spring data solr 3.0.6 release

I am trying to use Spring solr starter in spring boot using java based configuration. I have read official doc https://docs.spring.io/spring-data/solr/docs/current/reference/html/#solr.annotation , there is only a sample to connect EmbeddedSolrServerFactory using the below code:

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

would anyone help me how to connect to my solr server (not embedded one) by using java based configuration in spring data solr. Thanks in advance.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM