Commit 4d87bf1a by Nepxion

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

parent 1b4a111c
...@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator; ...@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
* @version 1.0 * @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.ConsulRegistration;
import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry; import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware; ...@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor; import com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor;
public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry { public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
private static final Logger LOG = LoggerFactory.getLogger(ConsulServiceRegistryDecorator.class);
private ConsulServiceRegistry serviceRegistry; private ConsulServiceRegistry serviceRegistry;
private ConfigurableApplicationContext applicationContext; private ConfigurableApplicationContext applicationContext;
private ConfigurableEnvironment environment; private ConfigurableEnvironment environment;
...@@ -34,8 +39,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry { ...@@ -34,8 +39,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public void register(ConsulRegistration registration) { public void register(ConsulRegistration registration) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onRegister(registration); 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); serviceRegistry.register(registration);
...@@ -45,8 +54,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry { ...@@ -45,8 +54,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public void deregister(ConsulRegistration registration) { public void deregister(ConsulRegistration registration) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onDeregister(registration); 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); serviceRegistry.deregister(registration);
...@@ -56,8 +69,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry { ...@@ -56,8 +69,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public void setStatus(ConsulRegistration registration, String status) { public void setStatus(ConsulRegistration registration, String status) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onSetStatus(registration, status); 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); serviceRegistry.setStatus(registration, status);
...@@ -72,8 +89,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry { ...@@ -72,8 +89,12 @@ public class ConsulServiceRegistryDecorator extends ConsulServiceRegistry {
public void close() { public void close() {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onClose(); RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onClose();
} catch (BeansException e) {
LOG.warn("Get bean for RegisterListenerExecutor failed, ignore to executor listener");
}
} }
serviceRegistry.close(); serviceRegistry.close();
......
...@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator; ...@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
* @version 1.0 * @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.EurekaRegistration;
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry; import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware; ...@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor; import com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor;
public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry { public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
private static final Logger LOG = LoggerFactory.getLogger(EurekaServiceRegistryDecorator.class);
private EurekaServiceRegistry serviceRegistry; private EurekaServiceRegistry serviceRegistry;
private ConfigurableApplicationContext applicationContext; private ConfigurableApplicationContext applicationContext;
private ConfigurableEnvironment environment; private ConfigurableEnvironment environment;
...@@ -32,8 +37,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry { ...@@ -32,8 +37,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public void register(EurekaRegistration registration) { public void register(EurekaRegistration registration) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onRegister(registration); 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); serviceRegistry.register(registration);
...@@ -43,8 +52,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry { ...@@ -43,8 +52,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public void deregister(EurekaRegistration registration) { public void deregister(EurekaRegistration registration) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onDeregister(registration); 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); serviceRegistry.deregister(registration);
...@@ -54,8 +67,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry { ...@@ -54,8 +67,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public void setStatus(EurekaRegistration registration, String status) { public void setStatus(EurekaRegistration registration, String status) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onSetStatus(registration, status); 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); serviceRegistry.setStatus(registration, status);
...@@ -70,8 +87,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry { ...@@ -70,8 +87,12 @@ public class EurekaServiceRegistryDecorator extends EurekaServiceRegistry {
public void close() { public void close() {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onClose(); RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onClose();
} catch (BeansException e) {
LOG.warn("Get bean for RegisterListenerExecutor failed, ignore to executor listener");
}
} }
serviceRegistry.close(); serviceRegistry.close();
......
...@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator; ...@@ -9,6 +9,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
* @version 1.0 * @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.ZookeeperRegistration;
import org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry; import org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware; ...@@ -18,6 +21,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor; import com.nepxion.discovery.plugin.framework.listener.register.RegisterListenerExecutor;
public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry { public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry {
private static final Logger LOG = LoggerFactory.getLogger(ZookeeperServiceRegistryDecorator.class);
private ZookeeperServiceRegistry serviceRegistry; private ZookeeperServiceRegistry serviceRegistry;
private ConfigurableApplicationContext applicationContext; private ConfigurableApplicationContext applicationContext;
private ConfigurableEnvironment environment; private ConfigurableEnvironment environment;
...@@ -34,8 +39,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry ...@@ -34,8 +39,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public void register(ZookeeperRegistration registration) { public void register(ZookeeperRegistration registration) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onRegister(registration); 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); serviceRegistry.register(registration);
...@@ -45,8 +54,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry ...@@ -45,8 +54,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public void deregister(ZookeeperRegistration registration) { public void deregister(ZookeeperRegistration registration) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onDeregister(registration); 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); serviceRegistry.deregister(registration);
...@@ -56,8 +69,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry ...@@ -56,8 +69,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public void setStatus(ZookeeperRegistration registration, String status) { public void setStatus(ZookeeperRegistration registration, String status) {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onSetStatus(registration, status); 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); serviceRegistry.setStatus(registration, status);
...@@ -72,8 +89,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry ...@@ -72,8 +89,12 @@ public class ZookeeperServiceRegistryDecorator extends ZookeeperServiceRegistry
public void close() { public void close() {
Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment); Boolean registerControlEnabled = PluginContextAware.isRegisterControlEnabled(environment);
if (registerControlEnabled) { if (registerControlEnabled) {
RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class); try {
registerListenerExecutor.onClose(); RegisterListenerExecutor registerListenerExecutor = applicationContext.getBean(RegisterListenerExecutor.class);
registerListenerExecutor.onClose();
} catch (BeansException e) {
LOG.warn("Get bean for RegisterListenerExecutor failed, ignore to executor listener");
}
} }
serviceRegistry.close(); serviceRegistry.close();
......
...@@ -11,6 +11,9 @@ package com.nepxion.discovery.plugin.framework.decorator; ...@@ -11,6 +11,9 @@ package com.nepxion.discovery.plugin.framework.decorator;
import java.util.List; 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.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -20,6 +23,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware; ...@@ -20,6 +23,8 @@ import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
import com.nepxion.discovery.plugin.framework.listener.discovery.DiscoveryListenerExecutor; import com.nepxion.discovery.plugin.framework.listener.discovery.DiscoveryListenerExecutor;
public class DiscoveryClientDecorator implements DiscoveryClient { public class DiscoveryClientDecorator implements DiscoveryClient {
private static final Logger LOG = LoggerFactory.getLogger(DiscoveryClientDecorator.class);
private DiscoveryClient discoveryClient; private DiscoveryClient discoveryClient;
private ConfigurableApplicationContext applicationContext; private ConfigurableApplicationContext applicationContext;
private ConfigurableEnvironment environment; private ConfigurableEnvironment environment;
...@@ -36,8 +41,12 @@ public class DiscoveryClientDecorator implements DiscoveryClient { ...@@ -36,8 +41,12 @@ public class DiscoveryClientDecorator implements DiscoveryClient {
Boolean discoveryControlEnabled = PluginContextAware.isDiscoveryControlEnabled(environment); Boolean discoveryControlEnabled = PluginContextAware.isDiscoveryControlEnabled(environment);
if (discoveryControlEnabled) { if (discoveryControlEnabled) {
DiscoveryListenerExecutor discoveryListenerExecutor = applicationContext.getBean(DiscoveryListenerExecutor.class); try {
discoveryListenerExecutor.onGetInstances(serviceId, instances); 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; return instances;
...@@ -53,8 +62,12 @@ public class DiscoveryClientDecorator implements DiscoveryClient { ...@@ -53,8 +62,12 @@ public class DiscoveryClientDecorator implements DiscoveryClient {
Boolean discoveryControlEnabled = PluginContextAware.isDiscoveryControlEnabled(environment); Boolean discoveryControlEnabled = PluginContextAware.isDiscoveryControlEnabled(environment);
if (discoveryControlEnabled) { if (discoveryControlEnabled) {
DiscoveryListenerExecutor discoveryListenerExecutor = applicationContext.getBean(DiscoveryListenerExecutor.class); try {
discoveryListenerExecutor.onGetServices(services); 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; 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