Josh
Josh

Reputation: 21

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.

Upvotes: 0

Views: 316

Answers (1)

Josh
Josh

Reputation: 21

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

Upvotes: 1

Related Questions