Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
51ea8afb
Commit
51ea8afb
authored
Oct 09, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set port on InstanceInfo to support random server.port.
fixes gh-570
parent
5065e475
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
2 deletions
+17
-2
EurekaDiscoveryClientConfiguration.java
...ud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
+17
-2
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
View file @
51ea8afb
...
...
@@ -16,9 +16,13 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
;
import
java.lang.reflect.Field
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
lombok.SneakyThrows
;
import
lombok.extern.apachecommons.CommonsLog
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.health.HealthAggregator
;
...
...
@@ -39,16 +43,16 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.core.Ordered
;
import
org.springframework.util.ReflectionUtils
;
import
com.netflix.appinfo.ApplicationInfoManager
;
import
com.netflix.appinfo.EurekaInstanceConfig
;
import
com.netflix.appinfo.HealthCheckHandler
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.EurekaClientConfig
;
import
lombok.extern.apachecommons.CommonsLog
;
/**
* @author Dave Syer
* @author Spencer Gibb
...
...
@@ -83,11 +87,15 @@ public class EurekaDiscoveryClientConfiguration implements SmartLifecycle, Order
@Autowired
private
EurekaClient
eurekaClient
;
@Autowired
private
InstanceInfo
instanceInfo
;
@Override
public
void
start
()
{
// only set the port if the nonSecurePort is 0 and this.port != 0
if
(
this
.
port
.
get
()
!=
0
&&
this
.
instanceConfig
.
getNonSecurePort
()
==
0
)
{
this
.
instanceConfig
.
setNonSecurePort
(
this
.
port
.
get
());
setInstanceInfoPort
();
}
// only initialize if nonSecurePort is greater than 0 and it isn't already running
...
...
@@ -114,6 +122,13 @@ public class EurekaDiscoveryClientConfiguration implements SmartLifecycle, Order
}
}
@SneakyThrows
private
void
setInstanceInfoPort
()
{
Field
port
=
ReflectionUtils
.
findField
(
InstanceInfo
.
class
,
"port"
);
ReflectionUtils
.
makeAccessible
(
port
);
port
.
setInt
(
this
.
instanceInfo
,
this
.
port
.
get
());
}
@Override
public
void
stop
()
{
if
(
this
.
applicationInfoManager
.
getInfo
()
!=
null
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment