Describe the bug Like already described in Issue3294 this issue still remains in newer versions.

Sample You can check my github repository if you need a further test.

spring-boot-starter-parent: 2.3.1.RELEASE spring-cloud-starter-netflix-eureka-server: 2.2.3.RELEASE spring-cloud: Hoxton.SR6

spring-boot-starter-parent: 2.3.1.RELEASE spring-cloud-netflix-eureka-client: 2.2.3.RELEASE.jar spring-cloud.version: Hoxton.SR6

Comment From: spencergibb

Can you describe what "no longer registers proper port" means? What does /eureka/apps say?

Comment From: kleenxcoder

Sure!

Assuming I make use of random port assignment for my eureka client, my application.properties hast set "server.port=0". In my current case the service uses port 49270.

Looking at eureka sever I can see one registered service "UP (1) - ..local:hello-service:0" under section "Instances currently registered with Eureka" I would expect to see "UP (1) - ..local:hello-service:49270" this what happens when I set server.port=49270 manually.

When I start the service a second time and runs on port 49271 the eureka server does not display a second registered server.

Hope this helps

Comment From: blueiceprj

Hi,

I have also this problem on my project.

server.port=${random.int(5000,5100)} // -> 5095

But the gateway and the registery services looking at this address : http://XXXXXXXX:5062

Comment From: blueiceprj

I found a solution about that issue and helped me.

https://www.javacodemonk.com/setting-a-random-port-in-spring-boot-application-at-startup-87022e01

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.SocketUtils;
import org.springframework.util.StringUtils;

public class SpringBootUtil {
    final static Logger log = LoggerFactory.getLogger(SpringBootUtil.class);

    public static void setRandomPort(int minPort, int maxPort) {
        try {
            final String userDefinedPort = System.getProperty("server.port", System.getenv("SERVER_PORT"));
            if(StringUtils.isEmpty(userDefinedPort)) {
                final int port = SocketUtils.findAvailableTcpPort(minPort, maxPort);  
                System.setProperty("server.port", String.valueOf(port));
                log.info("Random Server Port is set to {}.", port);
            }
        } catch( final IllegalStateException e) {
            log.warn("No port available in range 5000-5100. Default embedded server configuration will be used.");
        }
    }
}

And

SpringBootUtil.setRandomPort(5000, 5500); 
final SpringApplication app = new SpringApplication(DemoServiceApp.class);

Comment From: kleenxcoder

Seems like this is not an issue and works as designed. My solution/workaround is setting eureka instance-id manually eureka.instance.instanceId=${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${random.value}}

Comment From: yongschoi

// random server port server.port = 0

// application name spring.application.name = app-xxx

// random eureka instance name eureka.instance.instanceId = ${spring.application.name}:${random.value}