Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
4d87bf1a
Commit
4d87bf1a
authored
Jul 31, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复引入Spring Cloud Config后无法加载Bean的Bug
parent
1b4a111c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
0 deletions
+76
-0
discovery-plugin-framework-consul/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ConsulServiceRegistryDecorator.java
+21
-0
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/decorator/EurekaServiceRegistryDecorator.java
+21
-0
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ZookeeperServiceRegistryDecorator.java
+21
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/decorator/DiscoveryClientDecorator.java
+13
-0
No files found.
discovery-plugin-framework-consul/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ConsulServiceRegistryDecorator.java
View file @
4d87bf1a
...
...
@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
* @version 1.0
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.cloud.consul.serviceregistry.ConsulRegistration
;
import
org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import
com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor
;
public
class
ConsulServiceRegistryDecorator
extends
ConsulServiceRegistry
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ConsulServiceRegistryDecorator
.
class
);
private
ConsulServiceRegistry
serviceRegistry
;
private
ConfigurableApplicationContext
applicationContext
;
private
ConfigurableEnvironment
environment
;
...
...
@@ -34,8 +39,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public
void
register
(
ConsulRegistration
registration
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onRegister
(
registration
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
register
(
registration
);
...
...
@@ -45,8 +54,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public
void
deregister
(
ConsulRegistration
registration
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onDeregister
(
registration
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
deregister
(
registration
);
...
...
@@ -56,8 +69,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public
void
setStatus
(
ConsulRegistration
registration
,
String
status
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onSetStatus
(
registration
,
status
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
setStatus
(
registration
,
status
);
...
...
@@ -72,8 +89,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public
void
close
()
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onClose
();
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
close
();
...
...
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/decorator/EurekaServiceRegistryDecorator.java
View file @
4d87bf1a
...
...
@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
* @version 1.0
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration
;
import
org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import
com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor
;
public
class
EurekaServiceRegistryDecorator
extends
EurekaServiceRegistry
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
EurekaServiceRegistryDecorator
.
class
);
private
EurekaServiceRegistry
serviceRegistry
;
private
ConfigurableApplicationContext
applicationContext
;
private
ConfigurableEnvironment
environment
;
...
...
@@ -32,8 +37,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public
void
register
(
EurekaRegistration
registration
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onRegister
(
registration
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
register
(
registration
);
...
...
@@ -43,8 +52,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public
void
deregister
(
EurekaRegistration
registration
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onDeregister
(
registration
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
deregister
(
registration
);
...
...
@@ -54,8 +67,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public
void
setStatus
(
EurekaRegistration
registration
,
String
status
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onSetStatus
(
registration
,
status
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
setStatus
(
registration
,
status
);
...
...
@@ -70,8 +87,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public
void
close
()
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onClose
();
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
close
();
...
...
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ZookeeperServiceRegistryDecorator.java
View file @
4d87bf1a
...
...
@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
* @version 1.0
*/
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.cloud.zookeeper.serviceregistry.ZookeeperRegistration
;
import
org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import
com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor
;
public
class
ZookeeperServiceRegistryDecorator
extends
ZookeeperServiceRegistry
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ZookeeperServiceRegistryDecorator
.
class
);
private
ZookeeperServiceRegistry
serviceRegistry
;
private
ConfigurableApplicationContext
applicationContext
;
private
ConfigurableEnvironment
environment
;
...
...
@@ -34,8 +39,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public
void
register
(
ZookeeperRegistration
registration
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onRegister
(
registration
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
register
(
registration
);
...
...
@@ -45,8 +54,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public
void
deregister
(
ZookeeperRegistration
registration
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onDeregister
(
registration
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
deregister
(
registration
);
...
...
@@ -56,8 +69,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public
void
setStatus
(
ZookeeperRegistration
registration
,
String
status
)
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onSetStatus
(
registration
,
status
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
setStatus
(
registration
,
status
);
...
...
@@ -72,8 +89,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public
void
close
()
{
Boolean
registerControlEnabled
=
PluginContextAware
.
isRegisterControlEnabled
(
environment
);
if
(
registerControlEnabled
)
{
try
{
RegisterListenerExecutor
registerListenerExecutor
=
applicationContext
.
getBean
(
RegisterListenerExecutor
.
class
);
registerListenerExecutor
.
onClose
();
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for RegisterListenerExecutor failed, ignore to executor listener"
);
}
}
serviceRegistry
.
close
();
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/decorator/DiscoveryClientDecorator.java
View file @
4d87bf1a
...
...
@@ -11,6 +11,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -20,6 +23,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import
com.nepxion.discovery.plugin.framework.listener.discovery.DiscoveryListenerExecutor
;
public
class
DiscoveryClientDecorator
implements
DiscoveryClient
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
DiscoveryClientDecorator
.
class
);
private
DiscoveryClient
discoveryClient
;
private
ConfigurableApplicationContext
applicationContext
;
private
ConfigurableEnvironment
environment
;
...
...
@@ -36,8 +41,12 @@ public class DiscoveryClientDecorator implements DiscoveryClient {
Boolean
discoveryControlEnabled
=
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
);
if
(
discoveryControlEnabled
)
{
try
{
DiscoveryListenerExecutor
discoveryListenerExecutor
=
applicationContext
.
getBean
(
DiscoveryListenerExecutor
.
class
);
discoveryListenerExecutor
.
onGetInstances
(
serviceId
,
instances
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for DiscoveryListenerExecutor failed, ignore to executor listener"
);
}
}
return
instances
;
...
...
@@ -53,8 +62,12 @@ public class DiscoveryClientDecorator implements DiscoveryClient {
Boolean
discoveryControlEnabled
=
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
);
if
(
discoveryControlEnabled
)
{
try
{
DiscoveryListenerExecutor
discoveryListenerExecutor
=
applicationContext
.
getBean
(
DiscoveryListenerExecutor
.
class
);
discoveryListenerExecutor
.
onGetServices
(
services
);
}
catch
(
BeansException
e
)
{
LOG
.
warn
(
"Get bean for DiscoveryListenerExecutor failed, ignore to executor listener"
);
}
}
return
services
;
...
...
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