Spring Solr Auto-Configuration
Apache Solr is a search engine. Spring Boot offers basic auto-configuration for the Solr 5 client
library and the abstractions on top of it provided by Spring Data Solr.
There is a spring-bootstarter-data-solr “Starter” for collecting the dependencies in a convenient way.
default, the instance tries to connect to a server at localhost:8983/solr. The following example
shows how to inject a Solr bean:
@Component
public class MyBean {
private SolrClient solr;
@Autowired
public MyBean(SolrClient solr) {
this.solr = solr;
}
// ...
}
If you add your own @Bean of type SolrClient, it replaces the default.
earlier, the basic principle is that queries are automatically constructed for you based on method
names.
In fact, both Spring Data JPA and Spring Data Solr share the same common infrastructure. You
could take the JPA example from earlier and, assuming that City is now a @SolrDocument class rather
than a JPA @Entity, it works in the same way.
IP: For complete details of Spring Data Solr, refer to the reference documentation.
library and the abstractions on top of it provided by Spring Data Solr.
There is a spring-bootstarter-data-solr “Starter” for collecting the dependencies in a convenient way.
Connecting to Solr
You can inject an auto-configured SolrClient instance as you would any other Spring bean. Bydefault, the instance tries to connect to a server at localhost:8983/solr. The following example
shows how to inject a Solr bean:
@Component
public class MyBean {
private SolrClient solr;
@Autowired
public MyBean(SolrClient solr) {
this.solr = solr;
}
// ...
}
If you add your own @Bean of type SolrClient, it replaces the default.
Spring Data Solr Repositories
Spring Data includes repository support for Apache Solr. As with the JPA repositories discussedearlier, the basic principle is that queries are automatically constructed for you based on method
names.
In fact, both Spring Data JPA and Spring Data Solr share the same common infrastructure. You
could take the JPA example from earlier and, assuming that City is now a @SolrDocument class rather
than a JPA @Entity, it works in the same way.
IP: For complete details of Spring Data Solr, refer to the reference documentation.
Comments
Post a Comment