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
a96666b9
Commit
a96666b9
authored
Oct 08, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move DiscoveryClient creation so it is guarded.
Move it back to EurekaDiscoveryClientConfiguration. fixes gh-578
parent
5b3a9f8f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
146 additions
and
104 deletions
+146
-104
DiscoveryClientConfigServiceBootstrapConfiguration.java
...g/DiscoveryClientConfigServiceBootstrapConfiguration.java
+3
-1
DiscoveryClientConfiguration.java
...rk/cloud/netflix/eureka/DiscoveryClientConfiguration.java
+138
-0
EurekaClientAutoConfiguration.java
...k/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+2
-102
EurekaDiscoveryClientConfiguration.java
...ud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
+2
-0
ConditionalOnRefreshScopeTests.java
.../cloud/netflix/eureka/ConditionalOnRefreshScopeTests.java
+1
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfiguration.java
View file @
a96666b9
...
...
@@ -25,7 +25,9 @@ import org.springframework.cloud.client.ServiceInstance;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.config.client.ConfigClientProperties
;
import
org.springframework.cloud.config.client.ConfigServicePropertySourceLocator
;
import
org.springframework.cloud.netflix.eureka.DiscoveryClientConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.event.ContextRefreshedEvent
;
...
...
@@ -45,7 +47,7 @@ import lombok.extern.apachecommons.CommonsLog;
@ConditionalOnClass
({
EurekaClient
.
class
,
ConfigServicePropertySourceLocator
.
class
})
@ConditionalOnProperty
(
value
=
"spring.cloud.config.discovery.enabled"
,
matchIfMissing
=
false
)
@Configuration
@Import
(
EurekaClientAutoConfiguration
.
class
)
@Import
(
{
EurekaClientAutoConfiguration
.
class
,
DiscoveryClientConfiguration
.
class
}
)
@CommonsLog
public
class
DiscoveryClientConfigServiceBootstrapConfiguration
{
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/DiscoveryClientConfiguration.java
0 → 100644
View file @
a96666b9
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
cloud
.
netflix
.
eureka
;
import
com.netflix.appinfo.ApplicationInfoManager
;
import
com.netflix.appinfo.EurekaInstanceConfig
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.EurekaClientConfig
;
import
lombok.SneakyThrows
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.AllNestedConditions
;
import
org.springframework.boot.autoconfigure.condition.AnyNestedCondition
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.SearchStrategy
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.context.scope.refresh.RefreshScope
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* @author Spencer Gibb
*/
@Configuration
public
class
DiscoveryClientConfiguration
{
@Bean
public
DiscoveryClient
discoveryClient
(
EurekaInstanceConfig
config
,
EurekaClient
client
)
{
return
new
EurekaDiscoveryClient
(
config
,
client
);
}
@Configuration
@ConditionalOnMissingRefreshScope
protected
static
class
EurekaClientConfiguration
{
@Autowired
private
ApplicationContext
context
;
@Bean
(
destroyMethod
=
"shutdown"
)
@ConditionalOnMissingBean
(
value
=
EurekaClient
.
class
,
search
=
SearchStrategy
.
CURRENT
)
@SneakyThrows
public
EurekaClient
eurekaClient
(
ApplicationInfoManager
applicationInfoManager
,
EurekaClientConfig
config
,
EurekaInstanceConfig
instance
)
{
applicationInfoManager
.
initComponent
(
instance
);
return
new
CloudEurekaClient
(
applicationInfoManager
,
config
,
this
.
context
);
}
}
@Configuration
@ConditionalOnRefreshScope
protected
static
class
RefreshableEurekaClientConfiguration
{
@Autowired
private
ApplicationContext
context
;
@Bean
(
destroyMethod
=
"shutdown"
)
@ConditionalOnMissingBean
(
value
=
EurekaClient
.
class
,
search
=
SearchStrategy
.
CURRENT
)
@SneakyThrows
@org
.
springframework
.
cloud
.
context
.
config
.
annotation
.
RefreshScope
public
EurekaClient
eurekaClient
(
ApplicationInfoManager
applicationInfoManager
,
EurekaClientConfig
config
,
EurekaInstanceConfig
instance
)
{
applicationInfoManager
.
initComponent
(
instance
);
return
new
CloudEurekaClient
(
applicationInfoManager
,
config
,
this
.
context
);
}
}
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Conditional
(
OnMissingRefreshScopeCondition
.
class
)
@interface
ConditionalOnMissingRefreshScope
{
}
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Conditional
(
OnRefreshScopeCondition
.
class
)
@interface
ConditionalOnRefreshScope
{
}
private
static
class
OnMissingRefreshScopeCondition
extends
AnyNestedCondition
{
public
OnMissingRefreshScopeCondition
()
{
super
(
ConfigurationPhase
.
REGISTER_BEAN
);
}
@ConditionalOnMissingClass
(
"org.springframework.cloud.context.scope.refresh.RefreshScope"
)
static
class
MissingClass
{
}
@ConditionalOnMissingBean
(
RefreshScope
.
class
)
static
class
MissingScope
{
}
}
private
static
class
OnRefreshScopeCondition
extends
AllNestedConditions
{
public
OnRefreshScopeCondition
()
{
super
(
ConfigurationPhase
.
REGISTER_BEAN
);
}
@ConditionalOnClass
(
RefreshScope
.
class
)
@ConditionalOnBean
(
RefreshScope
.
class
)
static
class
FoundScope
{
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
a96666b9
...
...
@@ -18,36 +18,20 @@ package org.springframework.cloud.netflix.eureka;
import
static
org
.
springframework
.
cloud
.
util
.
IdUtils
.
getDefaultInstanceId
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
lombok.SneakyThrows
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.AllNestedConditions
;
import
org.springframework.boot.autoconfigure.condition.AnyNestedCondition
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.SearchStrategy
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.autoconfigure.RefreshAutoConfiguration
;
import
org.springframework.cloud.client.CommonsClientAutoConfiguration
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.context.scope.refresh.RefreshScope
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.ConfigurableEnvironment
;
...
...
@@ -59,6 +43,8 @@ import com.netflix.discovery.EurekaClientConfig;
/**
* @author Dave Syer
* @author Spencer Gibb
* @author Jon Schneider
*/
@Configuration
@EnableConfigurationProperties
...
...
@@ -108,90 +94,4 @@ public class EurekaClientAutoConfiguration {
return
new
InstanceInfoFactory
().
create
(
config
);
}
@Bean
public
DiscoveryClient
discoveryClient
(
EurekaInstanceConfig
config
,
EurekaClient
client
)
{
return
new
EurekaDiscoveryClient
(
config
,
client
);
}
@Configuration
@ConditionalOnMissingRefreshScope
protected
static
class
EurekaClientConfiguration
{
@Autowired
private
ApplicationContext
context
;
@Bean
(
destroyMethod
=
"shutdown"
)
@ConditionalOnMissingBean
(
value
=
EurekaClient
.
class
,
search
=
SearchStrategy
.
CURRENT
)
@SneakyThrows
public
EurekaClient
eurekaClient
(
ApplicationInfoManager
applicationInfoManager
,
EurekaClientConfig
config
,
EurekaInstanceConfig
instance
)
{
applicationInfoManager
.
initComponent
(
instance
);
return
new
CloudEurekaClient
(
applicationInfoManager
,
config
,
this
.
context
);
}
}
@Configuration
@ConditionalOnRefreshScope
protected
static
class
RefreshableEurekaClientConfiguration
{
@Autowired
private
ApplicationContext
context
;
@Bean
(
destroyMethod
=
"shutdown"
)
@ConditionalOnMissingBean
(
value
=
EurekaClient
.
class
,
search
=
SearchStrategy
.
CURRENT
)
@SneakyThrows
@org
.
springframework
.
cloud
.
context
.
config
.
annotation
.
RefreshScope
public
EurekaClient
eurekaClient
(
ApplicationInfoManager
applicationInfoManager
,
EurekaClientConfig
config
,
EurekaInstanceConfig
instance
)
{
applicationInfoManager
.
initComponent
(
instance
);
return
new
CloudEurekaClient
(
applicationInfoManager
,
config
,
this
.
context
);
}
}
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Conditional
(
OnMissingRefreshScopeCondition
.
class
)
@interface
ConditionalOnMissingRefreshScope
{
}
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Conditional
(
OnRefreshScopeCondition
.
class
)
@interface
ConditionalOnRefreshScope
{
}
private
static
class
OnMissingRefreshScopeCondition
extends
AnyNestedCondition
{
public
OnMissingRefreshScopeCondition
()
{
super
(
ConfigurationPhase
.
REGISTER_BEAN
);
}
@ConditionalOnMissingClass
(
"org.springframework.cloud.context.scope.refresh.RefreshScope"
)
static
class
MissingClass
{
}
@ConditionalOnMissingBean
(
RefreshScope
.
class
)
static
class
MissingScope
{
}
}
private
static
class
OnRefreshScopeCondition
extends
AllNestedConditions
{
public
OnRefreshScopeCondition
()
{
super
(
ConfigurationPhase
.
REGISTER_BEAN
);
}
@ConditionalOnClass
(
RefreshScope
.
class
)
@ConditionalOnBean
(
RefreshScope
.
class
)
static
class
FoundScope
{
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaDiscoveryClientConfiguration.java
View file @
a96666b9
...
...
@@ -38,6 +38,7 @@ import org.springframework.context.ApplicationContext;
import
org.springframework.context.SmartLifecycle
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.core.Ordered
;
...
...
@@ -59,6 +60,7 @@ import com.netflix.discovery.EurekaClientConfig;
@EnableConfigurationProperties
@ConditionalOnClass
(
EurekaClientConfig
.
class
)
@ConditionalOnProperty
(
value
=
"eureka.client.enabled"
,
matchIfMissing
=
true
)
@Import
(
DiscoveryClientConfiguration
.
class
)
@CommonsLog
public
class
EurekaDiscoveryClientConfiguration
implements
SmartLifecycle
,
Ordered
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/ConditionalOnRefreshScopeTests.java
View file @
a96666b9
...
...
@@ -24,7 +24,7 @@ import org.junit.After;
import
org.junit.Test
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.autoconfigure.RefreshAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.
EurekaClientAuto
Configuration.ConditionalOnRefreshScope
;
import
org.springframework.cloud.netflix.eureka.
DiscoveryClient
Configuration.ConditionalOnRefreshScope
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
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