1616
1717package org .springframework .cloud .netflix .eureka ;
1818
19+ import java .lang .reflect .Field ;
1920import java .util .concurrent .atomic .AtomicBoolean ;
2021import java .util .concurrent .atomic .AtomicInteger ;
2122
23+ import lombok .SneakyThrows ;
24+ import lombok .extern .apachecommons .CommonsLog ;
25+
2226import org .springframework .beans .factory .annotation .Autowired ;
2327import org .springframework .boot .actuate .endpoint .Endpoint ;
2428import org .springframework .boot .actuate .health .HealthAggregator ;
3943import org .springframework .context .event .ContextClosedEvent ;
4044import org .springframework .context .event .EventListener ;
4145import org .springframework .core .Ordered ;
46+ import org .springframework .util .ReflectionUtils ;
4247
4348import com .netflix .appinfo .ApplicationInfoManager ;
4449import com .netflix .appinfo .EurekaInstanceConfig ;
4550import com .netflix .appinfo .HealthCheckHandler ;
51+ import com .netflix .appinfo .InstanceInfo ;
4652import com .netflix .appinfo .InstanceInfo .InstanceStatus ;
4753import com .netflix .discovery .EurekaClient ;
4854import com .netflix .discovery .EurekaClientConfig ;
4955
50- import lombok .extern .apachecommons .CommonsLog ;
51-
5256/**
5357 * @author Dave Syer
5458 * @author Spencer Gibb
@@ -83,11 +87,15 @@ public class EurekaDiscoveryClientConfiguration implements SmartLifecycle, Order
8387 @ Autowired
8488 private EurekaClient eurekaClient ;
8589
90+ @ Autowired
91+ private InstanceInfo instanceInfo ;
92+
8693 @ Override
8794 public void start () {
8895 // only set the port if the nonSecurePort is 0 and this.port != 0
8996 if (this .port .get () != 0 && this .instanceConfig .getNonSecurePort () == 0 ) {
9097 this .instanceConfig .setNonSecurePort (this .port .get ());
98+ setInstanceInfoPort ();
9199 }
92100
93101 // only initialize if nonSecurePort is greater than 0 and it isn't already running
@@ -114,6 +122,13 @@ public void start() {
114122 }
115123 }
116124
125+ @ SneakyThrows
126+ private void setInstanceInfoPort () {
127+ Field port = ReflectionUtils .findField (InstanceInfo .class , "port" );
128+ ReflectionUtils .makeAccessible (port );
129+ port .setInt (this .instanceInfo , this .port .get ());
130+ }
131+
117132 @ Override
118133 public void stop () {
119134 if (this .applicationInfoManager .getInfo () != null ) {
0 commit comments