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
2dfee975
Commit
2dfee975
authored
Oct 25, 2016
by
Ryan Baxter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve spring.application.name value via a property resolver instead of @Value. Fixes #1398
parent
0235d779
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
18 deletions
+53
-18
EurekaClientAutoConfiguration.java
...k/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+8
-0
EurekaInstanceConfigBean.java
...mework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
+11
-14
EurekaInstanceConfigBeanTests.java
...k/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
+23
-2
SidecarConfiguration.java
...framework/cloud/netflix/sidecar/SidecarConfiguration.java
+11
-2
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
2dfee975
...
...
@@ -64,6 +64,7 @@ import static org.springframework.cloud.commons.util.IdUtils.getDefaultInstanceI
* @author Spencer Gibb
* @author Jon Schneider
* @author Matt Jenkins
* @author Ryan Baxter
*/
@Configuration
@EnableConfigurationProperties
...
...
@@ -107,9 +108,16 @@ public class EurekaClientAutoConfiguration {
@ConditionalOnMissingBean
(
value
=
EurekaInstanceConfig
.
class
,
search
=
SearchStrategy
.
CURRENT
)
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
);
instance
.
setNonSecurePort
(
this
.
nonSecurePort
);
instance
.
setInstanceId
(
getDefaultInstanceId
(
this
.
env
));
if
(
springAppName
!=
null
)
{
instance
.
setAppname
(
springAppName
);
instance
.
setVirtualHostName
(
springAppName
);
instance
.
setSecureVirtualHostName
(
springAppName
);
}
if
(
this
.
managementPort
!=
this
.
nonSecurePort
&&
this
.
managementPort
!=
0
)
{
if
(
StringUtils
.
hasText
(
this
.
hostname
))
{
instance
.
setHostname
(
this
.
hostname
);
...
...
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
View file @
2dfee975
...
...
@@ -16,31 +16,31 @@
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.Map
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.commons.util.InetUtils
;
import
org.springframework.cloud.commons.util.InetUtils.HostInfo
;
import
com.netflix.appinfo.DataCenterInfo
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
com.netflix.appinfo.MyDataCenterInfo
;
import
lombok.AccessLevel
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* @author Dave Syer
* @author Spencer Gibb
* @author Ryan Baxter
*/
@Data
@ConfigurationProperties
(
"eureka.instance"
)
public
class
EurekaInstanceConfigBean
implements
CloudEurekaInstanceConfig
{
private
static
final
String
UNKNOWN
=
"unknown"
;
@Getter
(
AccessLevel
.
PRIVATE
)
@Setter
(
AccessLevel
.
PRIVATE
)
private
HostInfo
hostInfo
;
...
...
@@ -52,8 +52,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
/**
* Get the name of the application to be registered with eureka.
*/
@Value
(
"${spring.application.name:unknown}"
)
private
String
appname
=
"unknown"
;
private
String
appname
=
UNKNOWN
;
/**
* Get the name of the application group to be registered with eureka.
...
...
@@ -119,8 +118,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
* virtual host name.Think of this as similar to the fully qualified domain name, that
* the users of your services will need to find this instance.
*/
@Value
(
"${spring.application.name:unknown}"
)
private
String
virtualHostName
;
private
String
virtualHostName
=
UNKNOWN
;
/**
* Get the unique Id (within the scope of the appName) of this instance to be
...
...
@@ -135,8 +133,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
* secure virtual host name.Think of this as similar to the fully qualified domain
* name, that the users of your services will need to find this instance.
*/
@Value
(
"${spring.application.name:unknown}"
)
private
String
secureVirtualHostName
;
private
String
secureVirtualHostName
=
UNKNOWN
;
/**
* Gets the AWS autoscaling group name associated with this instance. This information
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
View file @
2dfee975
...
...
@@ -20,15 +20,17 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.commons.util.InetUtils
;
import
org.springframework.cloud.commons.util.InetUtilsProperties
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
@@ -38,6 +40,7 @@ import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnviron
/**
* @author Dave Syer
* @author Spencer Gibb
* @author Ryan Baxter
*/
public
class
EurekaInstanceConfigBeanTests
{
...
...
@@ -185,6 +188,14 @@ public class EurekaInstanceConfigBeanTests {
}
@Test
public
void
testDefaultAppName
()
throws
Exception
{
setupContext
();
assertEquals
(
"default app name is wrong"
,
"unknown"
,
getInstanceConfig
().
getAppname
());
assertEquals
(
"default virtual hostname is wrong"
,
"unknown"
,
getInstanceConfig
().
getVirtualHostName
());
assertEquals
(
"default secure virtual hostname is wrong"
,
"unknown"
,
getInstanceConfig
().
getSecureVirtualHostName
());
}
private
void
setupContext
()
{
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
...
...
@@ -198,9 +209,19 @@ public class EurekaInstanceConfigBeanTests {
@Configuration
@EnableConfigurationProperties
protected
static
class
TestConfiguration
{
@Autowired
ConfigurableEnvironment
env
;
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
return
new
EurekaInstanceConfigBean
(
new
InetUtils
(
new
InetUtilsProperties
()));
EurekaInstanceConfigBean
configBean
=
new
EurekaInstanceConfigBean
(
new
InetUtils
(
new
InetUtilsProperties
()));
RelaxedPropertyResolver
springPropertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"spring.application."
);
String
springAppName
=
springPropertyResolver
.
getProperty
(
"name"
);
if
(
springAppName
!=
null
)
{
configBean
.
setSecureVirtualHostName
(
springAppName
);
configBean
.
setVirtualHostName
(
springAppName
);
configBean
.
setAppname
(
springAppName
);
}
return
configBean
;
}
}
...
...
spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarConfiguration.java
View file @
2dfee975
...
...
@@ -16,10 +16,13 @@
package
org
.
springframework
.
cloud
.
netflix
.
sidecar
;
import
static
org
.
springframework
.
cloud
.
commons
.
util
.
IdUtils
.
getDefaultInstanceId
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.commons.util.InetUtils
;
...
...
@@ -32,10 +35,9 @@ import org.springframework.util.StringUtils;
import
com.netflix.appinfo.HealthCheckHandler
;
import
com.netflix.discovery.EurekaClientConfig
;
import
static
org
.
springframework
.
cloud
.
commons
.
util
.
IdUtils
.
getDefaultInstanceId
;
/**
* @author Spencer Gibb
* @author Ryan Baxter
*/
@Configuration
@EnableConfigurationProperties
...
...
@@ -73,9 +75,16 @@ public class SidecarConfiguration {
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
EurekaInstanceConfigBean
config
=
new
EurekaInstanceConfigBean
(
inetUtils
);
RelaxedPropertyResolver
springPropertyResolver
=
new
RelaxedPropertyResolver
(
env
,
"spring.application."
);
String
springAppName
=
springPropertyResolver
.
getProperty
(
"name"
);
int
port
=
this
.
sidecarProperties
.
getPort
();
config
.
setNonSecurePort
(
port
);
config
.
setInstanceId
(
getDefaultInstanceId
(
this
.
env
));
if
(
StringUtils
.
hasText
(
springAppName
))
{
config
.
setAppname
(
springAppName
);
config
.
setVirtualHostName
(
springAppName
);
config
.
setSecureVirtualHostName
(
springAppName
);
}
if
(
StringUtils
.
hasText
(
this
.
hostname
))
{
config
.
setHostname
(
this
.
hostname
);
}
...
...
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