Commit 4d87bf1a by Nepxion

修复引入Spring Cloud Config后无法加载Bean的Bug

parent 1b4a111c
......@@ -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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onRegister(registration);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onDeregister(registration);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onSetStatus(registration, status);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onClose();
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();
......
......@@ -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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onRegister(registration);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onDeregister(registration);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onSetStatus(registration, status);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onClose();
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();
......
......@@ -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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onRegister(registration);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onDeregister(registration);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onSetStatus(registration, status);
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) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onClose();
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();
......
......@@ -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) {
DiscoveryListenerExecutor discoveryListenerExecutor = applicationContext.getBean(DiscoveryListenerExecutor.class);
discoveryListenerExecutor.onGetInstances(serviceId, instances);
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) {
DiscoveryListenerExecutor discoveryListenerExecutor = applicationContext.getBean(DiscoveryListenerExecutor.class);
discoveryListenerExecutor.onGetServices(services);
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment