com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect in Spring Boot

The problem might be you have not specified the correct port for Eureka server. If you don't specify the port it will try to use default port 8080 which will lead to errors. Use configuration as mentioned below in your application.properties file. 8761 is default port for eureka server

server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

Also make sure your annotate you main class as below

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }

}

Getting exception Connection refused . It means the server port number already running in background. Check your server port number running in background or not.

Follow this process:

May be running same port number in background, see and kill below commands in windows. Go to command prompt->Run below commands ,

Find open running ports:

C:\WINDOWS\system32>netstat -ano | findstr :Port number

Example: netstat -ano | findstr :8761

kill ports based on PID(process ID)

C:\WINDOWS\system32>taskkill /PID PIDNumber /F 

Example: taskkill /PID 3740 /F

Kill all running services using above commands and set port number and write below code in application.properties file.

server.port=8761

#set port number
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetchRegistry=false
eureka.client.server.waitTimeInMsWhenSyncEmpty=0

Just edit above lines. working fine.


Is EurekaServer running?

I had the same problem, the problem is I haven't running the Eureka Server. After running the Eureka Server it started working fine.