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
b3f1a300
Unverified
Commit
b3f1a300
authored
Oct 27, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move initalizing appname, etc.. to afterPropertiesSet
parent
111a95d2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
14 deletions
+41
-14
EurekaClientAutoConfiguration.java
...k/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+2
-8
EurekaInstanceConfigBean.java
...mework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
+30
-6
EurekaClientAutoConfigurationTests.java
...ud/netflix/eureka/EurekaClientAutoConfigurationTests.java
+9
-0
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
b3f1a300
...
@@ -111,21 +111,15 @@ public class EurekaClientAutoConfiguration {
...
@@ -111,21 +111,15 @@ public class EurekaClientAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
(
value
=
EurekaInstanceConfig
.
class
,
search
=
SearchStrategy
.
CURRENT
)
@ConditionalOnMissingBean
(
value
=
EurekaInstanceConfig
.
class
,
search
=
SearchStrategy
.
CURRENT
)
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
(
InetUtils
inetUtils
)
{
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
(
InetUtils
inetUtils
)
{
RelaxedPropertyResolver
relaxedPropertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"eureka.instance."
);
RelaxedPropertyResolver
springPropertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"spring.application."
);
String
springAppName
=
springPropertyResolver
.
getProperty
(
"name"
);
EurekaInstanceConfigBean
instance
=
new
EurekaInstanceConfigBean
(
inetUtils
);
EurekaInstanceConfigBean
instance
=
new
EurekaInstanceConfigBean
(
inetUtils
);
instance
.
setNonSecurePort
(
this
.
nonSecurePort
);
instance
.
setNonSecurePort
(
this
.
nonSecurePort
);
instance
.
setInstanceId
(
getDefaultInstanceId
(
this
.
env
));
instance
.
setInstanceId
(
getDefaultInstanceId
(
this
.
env
));
if
(
StringUtils
.
hasText
(
springAppName
))
{
instance
.
setAppname
(
springAppName
);
instance
.
setVirtualHostName
(
springAppName
);
instance
.
setSecureVirtualHostName
(
springAppName
);
}
if
(
this
.
managementPort
!=
this
.
nonSecurePort
&&
this
.
managementPort
!=
0
)
{
if
(
this
.
managementPort
!=
this
.
nonSecurePort
&&
this
.
managementPort
!=
0
)
{
if
(
StringUtils
.
hasText
(
this
.
hostname
))
{
if
(
StringUtils
.
hasText
(
this
.
hostname
))
{
instance
.
setHostname
(
this
.
hostname
);
instance
.
setHostname
(
this
.
hostname
);
}
}
RelaxedPropertyResolver
relaxedPropertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"eureka.instance."
);
String
statusPageUrlPath
=
relaxedPropertyResolver
.
getProperty
(
"statusPageUrlPath"
);
String
statusPageUrlPath
=
relaxedPropertyResolver
.
getProperty
(
"statusPageUrlPath"
);
String
healthCheckUrlPath
=
relaxedPropertyResolver
.
getProperty
(
"healthCheckUrlPath"
);
String
healthCheckUrlPath
=
relaxedPropertyResolver
.
getProperty
(
"healthCheckUrlPath"
);
if
(
StringUtils
.
hasText
(
statusPageUrlPath
))
{
if
(
StringUtils
.
hasText
(
statusPageUrlPath
))
{
...
...
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
View file @
b3f1a300
...
@@ -16,20 +16,27 @@
...
@@ -16,20 +16,27 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
;
package
org
.
springframework
.
cloud
.
netflix
.
eureka
;
import
lombok.AccessLevel
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.commons.util.InetUtils
;
import
org.springframework.cloud.commons.util.InetUtils
;
import
org.springframework.cloud.commons.util.InetUtils.HostInfo
;
import
org.springframework.cloud.commons.util.InetUtils.HostInfo
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.StringUtils
;
import
com.netflix.appinfo.DataCenterInfo
;
import
com.netflix.appinfo.DataCenterInfo
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
com.netflix.appinfo.MyDataCenterInfo
;
import
com.netflix.appinfo.MyDataCenterInfo
;
import
lombok.AccessLevel
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
/**
* @author Dave Syer
* @author Dave Syer
* @author Spencer Gibb
* @author Spencer Gibb
...
@@ -37,7 +44,7 @@ import com.netflix.appinfo.MyDataCenterInfo;
...
@@ -37,7 +44,7 @@ import com.netflix.appinfo.MyDataCenterInfo;
*/
*/
@Data
@Data
@ConfigurationProperties
(
"eureka.instance"
)
@ConfigurationProperties
(
"eureka.instance"
)
public
class
EurekaInstanceConfigBean
implements
CloudEurekaInstanceConfig
{
public
class
EurekaInstanceConfigBean
implements
CloudEurekaInstanceConfig
,
EnvironmentAware
,
InitializingBean
{
private
static
final
String
UNKNOWN
=
"unknown"
;
private
static
final
String
UNKNOWN
=
"unknown"
;
...
@@ -272,6 +279,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
...
@@ -272,6 +279,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
private
InstanceStatus
initialStatus
=
InstanceStatus
.
UP
;
private
InstanceStatus
initialStatus
=
InstanceStatus
.
UP
;
private
String
[]
defaultAddressResolutionOrder
=
new
String
[
0
];
private
String
[]
defaultAddressResolutionOrder
=
new
String
[
0
];
private
Environment
environment
;
public
String
getHostname
()
{
public
String
getHostname
()
{
return
getHostName
(
false
);
return
getHostName
(
false
);
...
@@ -319,4 +327,20 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
...
@@ -319,4 +327,20 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
}
}
return
this
.
preferIpAddress
?
this
.
ipAddress
:
this
.
hostname
;
return
this
.
preferIpAddress
?
this
.
ipAddress
:
this
.
hostname
;
}
}
@Override
public
void
setEnvironment
(
Environment
environment
)
{
this
.
environment
=
environment
;
}
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
RelaxedPropertyResolver
springPropertyResolver
=
new
RelaxedPropertyResolver
(
this
.
environment
,
"spring.application."
);
String
springAppName
=
springPropertyResolver
.
getProperty
(
"name"
);
if
(
StringUtils
.
hasText
(
springAppName
))
{
setAppname
(
springAppName
);
setVirtualHostName
(
springAppName
);
setSecureVirtualHostName
(
springAppName
);
}
}
}
}
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
View file @
b3f1a300
...
@@ -206,6 +206,15 @@ public class EurekaClientAutoConfigurationTests {
...
@@ -206,6 +206,15 @@ public class EurekaClientAutoConfigurationTests {
assertEquals
(
"mytest"
,
getInstanceConfig
().
getSecureVirtualHostName
());
assertEquals
(
"mytest"
,
getInstanceConfig
().
getSecureVirtualHostName
());
}
}
@Test
public
void
testAppNameUpper
()
throws
Exception
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"SPRING_APPLICATION_NAME=mytestupper"
);
setupContext
();
assertEquals
(
"mytestupper"
,
getInstanceConfig
().
getAppname
());
assertEquals
(
"mytestupper"
,
getInstanceConfig
().
getVirtualHostName
());
assertEquals
(
"mytestupper"
,
getInstanceConfig
().
getSecureVirtualHostName
());
}
private
void
testNonSecurePort
(
String
propName
)
{
private
void
testNonSecurePort
(
String
propName
)
{
addEnvironment
(
this
.
context
,
propName
+
":8888"
);
addEnvironment
(
this
.
context
,
propName
+
":8888"
);
setupContext
();
setupContext
();
...
...
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