Spring Boot 整合 Solr 设置项目启动时的默认连接路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38836118/article/details/84338030
<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-solrj</artifactId>
    <version>7.4.0</version>
</dependency>

问题描述:

       在Spring boot 项目中,启动时会默认连接 127.0.0.1:8983/solr, 而我在公司服务器上安装部署的solr,然后在自己电脑上上启动项目,就会导致启动时报连接失败的异常。

解决方式:

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-solr</artifactId>
</dependency>

首先在pom文件里引入依赖项

然后在application.yml里配置相关的地址

spring:
  data:
    solr:
      host: http://xxx.xxx.xx.xxx:8983/solr

然后

@Autowired
    private SolrClient solrClient;

再启动项目就会在启动时连接你设置的 http://xxx.xxx.xx.xxx:8983/solr

猜你喜欢

转载自blog.csdn.net/qq_38836118/article/details/84338030