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
61ea7843
Commit
61ea7843
authored
Dec 02, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added @EnableDiscoveryClient, deprecated @EnableEurekaClient
parent
79ceebb1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
14 deletions
+97
-14
EnableDiscoveryClient.java
...amework/cloud/client/discovery/EnableDiscoveryClient.java
+17
-0
EnableDiscoveryClientImportSelector.java
...client/discovery/EnableDiscoveryClientImportSelector.java
+59
-0
EnableEurekaClient.java
...ingframework/cloud/netflix/eureka/EnableEurekaClient.java
+1
-0
EurekaClientConfiguration.java
...ework/cloud/netflix/eureka/EurekaClientConfiguration.java
+13
-10
spring.factories
...netflix-core/src/main/resources/META-INF/spring.factories
+5
-2
Application.java
...ingframework/cloud/netflix/eureka/sample/Application.java
+2
-2
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClient.java
0 → 100644
View file @
61ea7843
package
org
.
springframework
.
cloud
.
client
.
discovery
;
/**
* @author Spencer Gibb
*/
import
org.springframework.context.annotation.Import
;
import
java.lang.annotation.*
;
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
@Import
(
EnableDiscoveryClientImportSelector
.
class
)
public
@interface
EnableDiscoveryClient
{
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/client/discovery/EnableDiscoveryClientImportSelector.java
0 → 100644
View file @
61ea7843
package
org
.
springframework
.
cloud
.
client
.
discovery
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.context.annotation.DeferredImportSelector
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.AnnotationAttributes
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.io.support.SpringFactoriesLoader
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.util.Assert
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
/**
* @author Spencer Gibb
*/
@Order
(
Ordered
.
LOWEST_PRECEDENCE
-
100
)
@Slf4j
public
class
EnableDiscoveryClientImportSelector
implements
DeferredImportSelector
,
BeanClassLoaderAware
{
private
ClassLoader
beanClassLoader
;
@Override
public
String
[]
selectImports
(
AnnotationMetadata
metadata
)
{
AnnotationAttributes
attributes
=
AnnotationAttributes
.
fromMap
(
metadata
.
getAnnotationAttributes
(
EnableDiscoveryClient
.
class
.
getName
(),
true
));
Assert
.
notNull
(
attributes
,
"No EnableDiscoveryClient attributes found. Is "
+
metadata
.
getClassName
()
+
" annotated with @EnableDiscoveryClient?"
);
// Find all possible auto configuration classes, filtering duplicates
List
<
String
>
factories
=
new
ArrayList
<>(
new
LinkedHashSet
<>(
SpringFactoriesLoader
.
loadFactoryNames
(
EnableDiscoveryClient
.
class
,
this
.
beanClassLoader
)));
if
(
factories
.
size
()
>
1
)
{
String
factory
=
factories
.
get
(
0
);
//there should only every be one DiscoveryClient
log
.
warn
(
"More than one implementation of @EnableDiscoveryClient. Using {} out of available {}"
,
factory
,
factories
);
factories
=
Collections
.
singletonList
(
factory
);
}
return
factories
.
toArray
(
new
String
[
factories
.
size
()]);
}
@Override
public
void
setBeanClassLoader
(
ClassLoader
classLoader
)
{
this
.
beanClassLoader
=
classLoader
;
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EnableEurekaClient.java
View file @
61ea7843
...
...
@@ -31,6 +31,7 @@ import org.springframework.context.annotation.Import;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Import
(
EurekaClientConfiguration
.
class
)
@Deprecated
public
@interface
EnableEurekaClient
{
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfiguration.java
View file @
61ea7843
...
...
@@ -43,6 +43,9 @@ import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import
com.netflix.discovery.DiscoveryManager
;
import
com.netflix.discovery.EurekaClientConfig
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
* @author Dave Syer
*
...
...
@@ -56,11 +59,11 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EurekaClientConfiguration
.
class
);
private
boolean
running
;
private
AtomicBoolean
running
=
new
AtomicBoolean
(
false
)
;
private
int
order
=
0
;
private
int
port
=
0
;
private
AtomicInteger
port
=
new
AtomicInteger
(
0
)
;
@Autowired
private
EurekaInstanceConfigBean
instanceConfig
;
...
...
@@ -80,12 +83,12 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
@Override
public
void
start
()
{
//only set the port if the nonSecurePort is 0 and this.port != 0
if
(
port
!=
0
&&
instanceConfig
.
getNonSecurePort
()
==
0
)
{
instanceConfig
.
setNonSecurePort
(
port
);
if
(
port
.
get
()
!=
0
&&
instanceConfig
.
getNonSecurePort
()
==
0
)
{
instanceConfig
.
setNonSecurePort
(
port
.
get
()
);
}
//only initialize if nonSecurePort is greater than 0 and it isn't already running
//because of containerPortInitializer below
if
(!
running
&&
instanceConfig
.
getNonSecurePort
()
>
0
)
{
if
(!
running
.
get
()
&&
instanceConfig
.
getNonSecurePort
()
>
0
)
{
discoveryManagerIntitializer
().
init
();
logger
.
info
(
"Registering application {} with eureka with status {}"
,
...
...
@@ -96,7 +99,7 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
DiscoveryManager
.
getInstance
().
getDiscoveryClient
().
registerHealthCheck
(
healthCheckHandler
);
}
context
.
publishEvent
(
new
InstanceRegisteredEvent
(
this
,
instanceConfig
));
running
=
true
;
running
.
set
(
true
)
;
}
}
...
...
@@ -105,12 +108,12 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
logger
.
info
(
"Unregistering application {} with eureka with status OUT_OF_SERVICE"
,
instanceConfig
.
getAppname
());
ApplicationInfoManager
.
getInstance
().
setInstanceStatus
(
InstanceStatus
.
OUT_OF_SERVICE
);
running
=
false
;
running
.
set
(
false
)
;
}
@Override
public
boolean
isRunning
()
{
return
running
;
return
running
.
get
()
;
}
@Override
...
...
@@ -159,8 +162,8 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
@Override
public
void
onApplicationEvent
(
EmbeddedServletContainerInitializedEvent
event
)
{
// TODO: take SSL into account when Spring Boot 1.2 is available
EurekaClientConfiguration
.
this
.
port
=
event
.
getEmbeddedServletContainer
()
.
getPort
();
EurekaClientConfiguration
.
this
.
port
.
compareAndSet
(
0
,
event
.
getEmbeddedServletContainer
()
.
getPort
()
)
;
EurekaClientConfiguration
.
this
.
start
();
}
};
...
...
spring-cloud-netflix-core/src/main/resources/META-INF/spring.factories
View file @
61ea7843
...
...
@@ -9,4 +9,7 @@ org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration,\
org.springframework.cloud.netflix.servo.ServoMetricsAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration
\ No newline at end of file
org.springframework.cloud.netflix.config.DiscoveryClientConfigServiceBootstrapConfiguration
org.springframework.cloud.client.discovery.EnableDiscoveryClient=\
org.springframework.cloud.netflix.eureka.EurekaClientConfiguration
\ No newline at end of file
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/sample/Application.java
View file @
61ea7843
...
...
@@ -4,7 +4,7 @@ import com.netflix.appinfo.HealthCheckHandler;
import
com.netflix.appinfo.InstanceInfo
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.
netflix.eureka.EnableEureka
Client
;
import
org.springframework.cloud.
client.discovery.EnableDiscovery
Client
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
@ComponentScan
@EnableAutoConfiguration
@RestController
@Enable
Eureka
Client
@Enable
Discovery
Client
public
class
Application
{
@Bean
...
...
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