For now, EurekaAutoServiceRegistration.SmartLifecycle isAutoStartup() is alwasy return true. So when spring context is start,eureka will register self instance info into eureka server. But when using embeded webserver,at this time ,web port may be not prepared to accept request. We found some request error for connection refused,and confirm the cause is eureka register before tomcat start up.

We also notice that in EurekaAutoServiceRegistration,there is a WebServerInitializedEvent listener,but when registration is already start,it will not re-register.

We try to set non-secrue-port to 0 for not start register when context is start. `
// only set the port if the nonSecurePort or securePort is 0 and this.port != 0 if (this.port.get() != 0) { if (this.registration.getNonSecurePort() == 0) { this.registration.setNonSecurePort(this.port.get()); }

if (this.registration.getSecurePort() == 0 && this.registration.isSecure()) {
    this.registration.setSecurePort(this.port.get());
}

} // only initialize if nonSecurePort is greater than 0 and it isn't already running // because of containerPortInitializer below if (!this.running.get() && this.registration.getNonSecurePort() > 0) {

    this.serviceRegistry.register(this.registration);

this.context.publishEvent(new InstanceRegisteredEvent<>(this,
this.registration.getInstanceConfig()));
this.running.set(true);

}` but it seems not working.We found this.registration.setNonSecurePort(this.port.get()); wont change the InstanceInfo in EurekaClient,there is diferrent InstanceInfo between EurekaClient & EurekaRegistration.

Now we using aop to change this behavior,like this. But we think the best practice is make this auto startup property configurable @Around("bean(eurekaAutoServiceRegistration) && execution(boolean org.springframework.context.SmartLifecycle.isAutoStartup())") public Object around(ProceedingJoinPoint pjp){ return false; }

Comment From: spencergibb

Duplicates #3833