Spring Data Solr 和 Spring Data JPA 的使用方法基本一致.
引入POM依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-solr</artifactId> </dependency>
实体类:
Spring Data Solr 3.0 以上版本不能使用 solrCoreName(通过查看源码可以知道,该注解已经过时.) 使用collection代替.
@Data @SolrDocument(collection = "new_core") public class Product { @Id @Indexed(name = "product_id", type = "string") private String id; @Indexed(name = "product_name", type = "string") private String name; }
Repository:
public interface SolrProductRepository extends SolrCrudRepository<Product, String> { }
yml配置:
spring: data: solr: host: http://localhost:8983/solr