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
c4a53a52
Commit
c4a53a52
authored
Oct 30, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use injected ConfigClientProperties to set defaults
parent
1f2beba0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
13 deletions
+19
-13
DiscoveryClientConfigServiceBootstrapConfiguration.java
...g/DiscoveryClientConfigServiceBootstrapConfiguration.java
+14
-6
DiscoveryClientConfigServiceBootstrapConfigurationTests.java
...coveryClientConfigServiceBootstrapConfigurationTests.java
+5
-7
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfiguration.java
View file @
c4a53a52
...
...
@@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.cloud.config.client.ConfigClientProperties
;
import
org.springframework.cloud.config.client.ConfigServicePropertySourceLocator
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
...
...
@@ -27,6 +28,8 @@ import org.springframework.context.ApplicationListener;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.event.ContextRefreshedEvent
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.Environment
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.discovery.DiscoveryClient
;
...
...
@@ -46,25 +49,30 @@ public class DiscoveryClientConfigServiceBootstrapConfiguration implements
@Autowired
private
DiscoveryClient
client
;
@Autowired
private
Config
ServicePropertySourceLocator
delegate
;
private
Config
ClientProperties
config
;
@Override
public
void
onApplicationEvent
(
ContextRefreshedEvent
event
)
{
try
{
log
.
info
(
"Locating configserver via discovery"
);
InstanceInfo
server
=
client
.
getNextServerFromEureka
(
delegate
.
getDiscovery
().
getServiceId
(),
Environment
environment
=
event
.
getApplicationContext
().
getEnvironment
();
if
(!(
environment
instanceof
ConfigurableEnvironment
))
{
log
.
info
(
"Environment is not ConfigurableEnvironment so cannot look up configserver"
);
return
;
}
InstanceInfo
server
=
client
.
getNextServerFromEureka
(
config
.
getDiscovery
().
getServiceId
(),
false
);
String
url
=
server
.
getHomePageUrl
();
if
(
server
.
getMetadata
().
containsKey
(
"password"
))
{
String
user
=
server
.
getMetadata
().
get
(
"user"
);
user
=
user
==
null
?
"user"
:
user
;
delegate
.
setUsername
(
user
);
config
.
setUsername
(
user
);
String
password
=
server
.
getMetadata
().
get
(
"password"
);
delegate
.
setPassword
(
password
);
config
.
setPassword
(
password
);
}
delegate
.
setUri
(
url
);
config
.
setUri
(
url
);
}
catch
(
Exception
e
)
{
log
.
warn
(
"Could not locate configserver via discovery"
,
e
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfigurationTests.java
View file @
c4a53a52
...
...
@@ -22,7 +22,7 @@ import org.junit.Test;
import
org.mockito.Mockito
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.cloud.config.client.Config
ServicePropertySourceLocator
;
import
org.springframework.cloud.config.client.Config
ClientProperties
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
com.netflix.appinfo.InstanceInfo
;
...
...
@@ -67,8 +67,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
1
,
context
.
getBeanNamesForType
(
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
).
length
);
Mockito
.
verify
(
client
).
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
);
ConfigServicePropertySourceLocator
locator
=
context
.
getBean
(
ConfigServicePropertySourceLocator
.
class
);
ConfigClientProperties
locator
=
context
.
getBean
(
ConfigClientProperties
.
class
);
assertEquals
(
"http://foo:7001/"
,
locator
.
getUri
());
}
...
...
@@ -78,8 +77,7 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
Mockito
.
when
(
client
.
getNextServerFromEureka
(
"CONFIGSERVER"
,
false
)).
thenReturn
(
info
);
setup
(
"spring.cloud.config.discovery.enabled=true"
);
ConfigServicePropertySourceLocator
locator
=
context
.
getBean
(
ConfigServicePropertySourceLocator
.
class
);
ConfigClientProperties
locator
=
context
.
getBean
(
ConfigClientProperties
.
class
);
assertEquals
(
"http://foo:7001/"
,
locator
.
getUri
());
assertEquals
(
"bar"
,
locator
.
getPassword
());
assertEquals
(
"user"
,
locator
.
getUsername
());
...
...
@@ -92,8 +90,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
client
);
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
,
Config
ServicePropertySourceLocator
.
class
);
context
.
refresh
();
Config
ClientProperties
.
class
);
context
.
refresh
();
}
}
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