1.引入Maven坐标
<!-- solr-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
2.全局配置文件
spring.data.solr.zk-host=192.168.110.134:2181,192.168.110.134:2183,192.168.110.134:2183
spring.data.solr.repositories.enabled=true
3.基于SpringdataJPA的方式 ,比较方便
@Service
public interface ProsSolrService extends SolrCrudRepository<ProsSolr, String> {
@Query(" item_title:*?0* ")
public List<ProsSolr> findByQueryAnnotation(String item_title);
}
4.启动类 :加上注解 指定ProsSolrService 的包名
@EnableSolrRepositories("com.ali.pservice")
调用:
@RestController
public class SolrController implements ApiSolr {
@Autowired
private ProsSolrService solrService;
@Override
public List<ProsSolr> solrCloud(@RequestParam String title) {
return solrService.findByQueryAnnotation(title);
}
}
报错 java.lang.ClassNotFoundException: javax.persistence.Table
加上坐标:
<!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>