Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.