Skip to content

Instantly share code, notes, and snippets.

@paulwellnerbou
Created August 21, 2018 07:14
Show Gist options
  • Save paulwellnerbou/2c76f6af40b677bfc69c8fad06e441d6 to your computer and use it in GitHub Desktop.
Save paulwellnerbou/2c76f6af40b677bfc69c8fad06e441d6 to your computer and use it in GitHub Desktop.
package de.wellnerbou.solr;
import de.wellnerbou.solr.CollectionAwareEntityInformationFacade;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.data.solr.server.SolrClientFactory;
import org.springframework.data.solr.server.support.HttpSolrClientFactory;
import javax.annotation.Resource;
@Configuration
public class YourSolrContext {
@Bean
@Resource
@Autowired
public YourRepository solrRepository(final SolrTemplate solrTemplate, final @Value("${solr.core}") String solrCore) {
return new YourRepository(solrTemplate, new CollectionAwareEntityInformationFacade<>(YourSolrDocument.class, solrCore));
}
@Bean
@Autowired
public SolrTemplate solrTemplate(final SolrClientFactory solrClientFactory) {
return new SolrTemplate(solrClientFactory);
}
@Bean
@Autowired
public SolrClient solrClient(final @Value("${solr.host:http://localhost:8983/solr/}") String solrHost) {
return new HttpSolrClient.Builder().withBaseSolrUrl(solrHost).build();
}
@Bean
@Autowired
public SolrClientFactory solrClientFactory(final SolrClient solrClient) {
return new HttpSolrClientFactory(solrClient);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment