1、添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
2、配置文件里加上
spring.data.solr.host=http://10.41.152.22:8080/solr/collection1
3、测试
package com.qf.test.deploy;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestDeployApplicationTests {
@Autowired
private HttpSolrClient solrClient;
@Test
public void contextLoads() throws Exception{
SolrQuery query = new SolrQuery();
query.setQuery("短夹克");
query.set("df", "solr_keywords");
QueryResponse response = solrClient.query(query);
SolrDocumentList results = response.getResults();
for (SolrDocument document: results) {
System.out.println(document.get("solr_name").toString());
}
}
}