简体   繁体   English

java.net.ConnectException:连接被拒绝:用 Spring boot 连接 Solr

[英]java.net.ConnectException: Connection refused: connect Solr with Spring boot

I am new to solr.我是 solr 的新手。 I am try to get record from table using rest call using solr spring data tool.我尝试使用 solr spring 数据工具使用 rest 调用从表中获取记录。 But when I am try to request url from browser then I am get the following error.但是当我尝试从浏览器请求 url 时,我收到以下错误。

java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method) ~[na:1.8.0_25]
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79) ~[na:1.8.0_25]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) ~[na:1.8.0_25]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_25]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_25]
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_25]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_25]
    at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_25]

My code is like as:我的代码是这样的:

User Object:用户对象:

public class User {

    @Field
    private String id;

    @Field
    private String fName;

    @Field
    private String lName;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getfName() {
        return fName;
    }

    public void setfName(String fName) {
        this.fName = fName;
    }

    public String getlName() {
        return lName;
    }

    public void setlName(String lName) {
        this.lName = lName;
    }
}

UserDao:用户道:

public interface UserDao extends SolrCrudRepository<User, Long> {

}

UserController:用户控制器:

@RestController
@RequestMapping("/app/api")
public class UserController {

    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public AjaxResponse loadAll() throws IOException {

        List<User> users = (List<User>) userDao.findAll();
        return new AjaxResponse("Success", false, users);
    }
}

Aplication.properties file: Application.properties 文件:

server.port=9111

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/solrDatabase?autoReconnect=true
spring.datasource.username=root
spring.datasource.password=root

spring.data.solr.host=http://localhost:8983/solr/
spring.data.solr.repositories.enabled=true

When I am try to request this url: http://localhost:9111/app/api/users Then I am getting exception.当我尝试请求此 url 时: http://localhost:9111/app/api/users然后我收到异常。 Can any one help me.谁能帮我。

The java.net.ConnectException: Connection refused: connect exception is thrown because your Spring application is unable to connect to your Solr server. java.net.ConnectException: Connection refused: connect异常被抛出,因为您的 Spring 应用程序无法连接到您的 Solr 服务器。 Since the URL you've provided, http://localhost:8983/solr/ does not work when you're opening it in the browser either, Solr is probably not running (as long as you're trying to connect from the same host as the code is running on, which from your other example URL seems to be true).由于您提供的 URL, http://localhost:8983/solr/在您在浏览器中打开它时也不起作用,Solr 可能没有运行(只要您尝试从相同的当代码运行时主机,从您的其他示例 URL 看来,这似乎是正确的)。

Make sure that Solr is actually running and able to answer requests before making any changes to your application.在对应用程序进行任何更改之前,请确保 Solr 实际正在运行并且能够响应请求。

Add the following properties into application.properties :将以下属性添加到application.properties

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.sun.jersey.api.client.ClientHandlerException:java.net.ConnectException:连接被拒绝:在 Spring Boot 中连接 - com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect in Spring Boot java.net.ConnectException:连接被拒绝(连接被拒绝):Docker + Spring 启动 - java.net.ConnectException: Connection refused (Connection refused): Docker + Spring boot docker容器内的spring boot引发java.net.ConnectException:连接被拒绝(连接被拒绝) - Spring boot inside docker container throws java.net.ConnectException: Connection refused (Connection refused) Docker 组成 Redis 和 Spring 启动应用程序:java.net.ConnectException:连接被拒绝(连接被拒绝)“, - Docker compose Redis and Spring boot app: java.net.ConnectException: Connection refused (Connection refused)", Spring Boot 微服务中的 Docker 连接问题 - 嵌套异常是 java.net.ConnectException: Connection refused: configserver - Docker Connection Issue in Spring Boot Microservice - nested exception is java.net.ConnectException: Connection refused : configserver Java Mail错误:java.net.ConnectException:连接被拒绝:connect - Java Mail Error : java.net.ConnectException: Connection refused: connect Java套接字 - java.net.ConnectException:连接被拒绝:连接 - Java sockets - java.net.ConnectException: Connection refused: connect Java网络问题:java.net.ConnectException:连接被拒绝:连接 - Java Networking Problem: java.net.ConnectException: Connection refused: connect Java 中的 ssh 异常:java.net.ConnectException:连接被拒绝:连接 - ssh Exception in Java: java.net.ConnectException: Connection refused: connect java.net.ConnectException:连接被拒绝:connect java nio - java.net.ConnectException: Connection refused: connect java nio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM