Configure Spring with Solr

You can use Spring Data Solr for Solr with your app. First, determine the Solr client using the Java configuration reader library.

import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import sh.platform.config.Config;
import sh.platform.config.Solr;
public class SolrConfig {
    public HttpSolrClient elasticsearchTemplate() {
        Config config = new Config();
        final Solr credential = config.getCredential("solr", Solr::new);
        final HttpSolrClient httpSolrClient = credential.get();
        String url = httpSolrClient.getBaseURL();
        httpSolrClient.setBaseURL(url.substring(0, url.lastIndexOf('/')));
        return httpSolrClient;
    public SolrTemplate solrTemplate(HttpSolrClient client) {
        return new SolrTemplate(client);