I was documenting my code that i wrote following some tutorials on Spring data for solr apache, and i realised i didn't know the diference between a solrTemplate
and a SolrClient
?
i was documenting the following code:
@Configuration
@EnableSolrRepositories(basePackages = {"com.anouar.solr.nomenclaturespringdatasolr.repository",
"com.anouar.solr.nomenclaturespringdatasolr.dataImportHandler"},
namedQueriesLocation = "classpath:solr-named-queries.properties")
public class SolrConfig {
@Value("${spring.data.solr.host}")
String solrURL;
/**
* returns the bean that establishes the connection with Solr through port 8983
*
* @return SolrClient
*
* **/
@Bean
public SolrClient solrClient() {
return new HttpSolrClient.Builder(solrURL).build();
}
/**
*
* @param client the bean that is connected to Solr through port 8983
*
* **/
@Bean
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
return new SolrTemplate(client);
}
}
Below is the description from apache documentation for SolrClient
Abstraction through which all communication with a Solr server may be routed
which means all your solr calls will be route via solrClient so we need to configure solr server address, port(few other also) to solrClient
.
where as solrTemplate
is for solr operations like query, count, etc.. solrTemplate
will use solrClient
that's why while configuring solrTemplate
, solrClient
is passed.
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.