diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/classloader/ClassLoaderManager.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/classloader/ClassLoaderManager.java index c7b2c65835..04a719387f 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/classloader/ClassLoaderManager.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/classloader/ClassLoaderManager.java @@ -45,6 +45,8 @@ public class ClassLoaderManager { private static FrameworkClassLoader frameworkClassLoader; + private static ClassLoader userClassLoader; + private ClassLoaderManager() { } @@ -88,6 +90,23 @@ public PluginClassLoader run() { }); } + public static void setUserClassLoader(ClassLoader userClassLoader) { + ClassLoaderManager.userClassLoader = userClassLoader; + } + + /** + * get ContextClassLoader or UserClassLoader + * + * @return ClassLoader + */ + public static ClassLoader getContextClassLoaderOrUserClassLoader() { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if (classLoader != null) { + return classLoader; + } + return userClassLoader; + } + public static SermantClassLoader getSermantClassLoader() { return sermantClassLoader; } diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/ClassLoaderLoadClassInterceptor.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/ClassLoaderLoadClassInterceptor.java index 287f0be05d..aa79320034 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/ClassLoaderLoadClassInterceptor.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/agent/enhance/ClassLoaderLoadClassInterceptor.java @@ -47,6 +47,7 @@ public ClassLoaderLoadClassInterceptor() { @Override public ExecuteContext before(ExecuteContext context) throws Exception { + ClassLoaderManager.setUserClassLoader((ClassLoader) context.getObject()); return context; } diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java index 85a01fa674..6d76a9e998 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/classloader/PluginClassLoader.java @@ -16,6 +16,7 @@ package io.sermant.core.plugin.classloader; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.config.ConfigManager; import io.sermant.core.plugin.agent.config.AgentConfig; @@ -133,9 +134,16 @@ public Class loadClass(String name, boolean resolve) throws ClassNotFoundExce private Class getClassFromLocalClassLoader(String name) { ClassLoader loader = localLoader.get(Thread.currentThread().getId()); - + if (loader == null) { + LOGGER.log(Level.FINE, "localLoader is null, thread name is {0}, classs name is {1}.", + new Object[]{Thread.currentThread().getName(), name}); + } if (loader == null && useContextLoader) { - loader = Thread.currentThread().getContextClassLoader(); + loader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); + if (loader == null) { + LOGGER.log(Level.WARNING, "contextClassLoader is null, thread name is {0}, classs name is {1}.", + new Object[]{Thread.currentThread().getName(), name}); + } } Class clazz = null; diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/IntegratedEventListenerAdapter.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/IntegratedEventListenerAdapter.java index fe5de74c33..c00d001f6c 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/IntegratedEventListenerAdapter.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/plugin/subscribe/processor/IntegratedEventListenerAdapter.java @@ -17,6 +17,7 @@ package io.sermant.core.plugin.subscribe.processor; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.service.dynamicconfig.common.DynamicConfigEvent; import io.sermant.core.service.dynamicconfig.common.DynamicConfigListener; @@ -43,7 +44,7 @@ public class IntegratedEventListenerAdapter implements DynamicConfigListener { public IntegratedEventListenerAdapter(ConfigProcessor processor, String rawGroup) { this.processor = processor; this.rawGroup = rawGroup; - this.classLoader = Thread.currentThread().getContextClassLoader(); + this.classLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); } @Override @@ -54,7 +55,7 @@ public void process(DynamicConfigEvent event) { // The classloader at subscription time may not be the same as the classloader at listener configuration // time, so need to restore it - ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader currentClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); try { Thread.currentThread().setContextClassLoader(classLoader); processor.process(rawGroup, event); diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ClassUtils.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ClassUtils.java index cb21315702..d77c8fec2e 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ClassUtils.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ClassUtils.java @@ -17,6 +17,7 @@ package io.sermant.core.utils; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import java.io.IOException; @@ -111,7 +112,7 @@ public static Optional> loadClass(String className, ClassLoader classLo public static Optional createInstance(String className, ClassLoader classLoader, Class[] paramTypes) { ClassLoader curClassLoader = classLoader; if (curClassLoader == null) { - curClassLoader = Thread.currentThread().getContextClassLoader(); + curClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); } try { final Class clazz = curClassLoader.loadClass(className); diff --git a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ReflectUtils.java b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ReflectUtils.java index 5507a4f73b..bf38d0870f 100644 --- a/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ReflectUtils.java +++ b/sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/utils/ReflectUtils.java @@ -17,6 +17,7 @@ package io.sermant.core.utils; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import java.lang.reflect.AccessibleObject; @@ -166,7 +167,7 @@ private static Optional> loadClass(String className) { return Optional.empty(); } return CLASS_CACHE.computeIfAbsent(className, value -> { - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); try { return Optional.ofNullable(contextClassLoader.loadClass(className)); } catch (ClassNotFoundException ignored) { diff --git a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/config/SermantYamlConstructor.java b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/config/SermantYamlConstructor.java index dd54b33100..3c555e81e0 100644 --- a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/config/SermantYamlConstructor.java +++ b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/config/SermantYamlConstructor.java @@ -16,6 +16,7 @@ package io.sermant.implement.config; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.exception.SermantRuntimeException; import org.yaml.snakeyaml.LoaderOptions; @@ -35,7 +36,7 @@ public class SermantYamlConstructor extends Constructor { */ public SermantYamlConstructor() { super(Object.class, new LoaderOptions()); - loader = Thread.currentThread().getContextClassLoader(); + loader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); } /** diff --git a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/nacos/NacosBufferedClient.java b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/nacos/NacosBufferedClient.java index 3d131aeffe..567f91a7a0 100644 --- a/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/nacos/NacosBufferedClient.java +++ b/sermant-agentcore/sermant-agentcore-implement/src/main/java/io/sermant/implement/service/dynamicconfig/nacos/NacosBufferedClient.java @@ -22,6 +22,7 @@ import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.client.auth.impl.NacosAuthLoginConstant; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.config.ConfigManager; import io.sermant.core.service.dynamicconfig.config.DynamicConfig; @@ -229,7 +230,7 @@ private Properties createProperties(String connectString, int sessionTimeout, St * @throws NacosInitException Connect to Nacos failed */ private void createNacosClient(String connectString, Properties properties) { - ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader tempClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); try { nacosClient = new NacosClient(properties); diff --git a/sermant-integration-tests/spring-test/spring-common/src/main/java/io/sermant/spring/common/loadbalancer/consumer/RibbonLbController.java b/sermant-integration-tests/spring-test/spring-common/src/main/java/io/sermant/spring/common/loadbalancer/consumer/RibbonLbController.java index 96d722e2ee..357ff72a0b 100644 --- a/sermant-integration-tests/spring-test/spring-common/src/main/java/io/sermant/spring/common/loadbalancer/consumer/RibbonLbController.java +++ b/sermant-integration-tests/spring-test/spring-common/src/main/java/io/sermant/spring/common/loadbalancer/consumer/RibbonLbController.java @@ -65,7 +65,7 @@ public String getRibbonLb(@RequestParam("serviceName") String serviceName) throw if (!RIBBON_CLASS.equals(loadBalancerClient.getClass().getName())) { return ERROR_RESPONSE; } - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final Class ribbonClientClass = contextClassLoader.loadClass(RIBBON_CLASS); final Field clientField = ReflectionUtils.findField(ribbonClientClass, "clientFactory"); if (clientField == null) { diff --git a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/inject/DynamicClassInjectDefine.java b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/inject/DynamicClassInjectDefine.java index f8edfb0b47..464f304f50 100644 --- a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/inject/DynamicClassInjectDefine.java +++ b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/inject/DynamicClassInjectDefine.java @@ -17,6 +17,7 @@ package io.sermant.dynamic.config.inject; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.service.inject.ClassInjectDefine; import io.sermant.core.utils.ClassUtils; @@ -42,6 +43,6 @@ public Plugin plugin() { @Override public boolean canInject() { return PluginConfigManager.getPluginConfig(DynamicConfiguration.class).isEnableDynamicConfig() - && ClassUtils.loadClass(REFRESH_CLASS, Thread.currentThread().getContextClassLoader()).isPresent(); + && ClassUtils.loadClass(REFRESH_CLASS, ClassLoaderManager.getContextClassLoaderOrUserClassLoader()).isPresent(); } } diff --git a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/interceptors/SpringFactoriesInterceptor.java b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/interceptors/SpringFactoriesInterceptor.java index 8c3e82ac46..299b167cd4 100644 --- a/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/interceptors/SpringFactoriesInterceptor.java +++ b/sermant-plugins/sermant-dynamic-config/dynamic-config-plugin/src/main/java/io/sermant/dynamic/config/interceptors/SpringFactoriesInterceptor.java @@ -17,6 +17,7 @@ package io.sermant.dynamic.config.interceptors; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.service.ServiceManager; @@ -94,7 +95,7 @@ private boolean isHasMethodLoadSpringFactories() { private void injectConfigurationsWithLowVersion(Object result, String factoryName) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); if (result instanceof List) { final List convertedResult = (List) result; CLASS_DEFINES.forEach(classInjectDefine -> { @@ -108,7 +109,7 @@ private void injectConfigurationsWithLowVersion(Object result, String factoryNam private void injectConfigurations(Object result) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final boolean isMultiValueMap = result instanceof MultiValueMap; if (result instanceof Map) { // spring 高版本处理, 针对List其为不可变list,需做一层处理 diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/io/sermant/flowcontrol/common/handler/retry/AbstractRetry.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/io/sermant/flowcontrol/common/handler/retry/AbstractRetry.java index d9b31925c6..979fb3949e 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/io/sermant/flowcontrol/common/handler/retry/AbstractRetry.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-common/src/main/java/io/sermant/flowcontrol/common/handler/retry/AbstractRetry.java @@ -17,6 +17,7 @@ package io.sermant.flowcontrol.common.handler.retry; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.service.xds.entity.XdsRetryPolicy; @@ -57,7 +58,8 @@ protected final Class[] findClass(String[] classNames) { final List> result = new ArrayList<>(classNames.length); for (String className : classNames) { try { - result.add(Class.forName(className, false, Thread.currentThread().getContextClassLoader())); + result.add(Class.forName(className, false, + ClassLoaderManager.getContextClassLoaderOrUserClassLoader())); } catch (ClassNotFoundException exception) { LoggerFactory.getLogger().info(String.format(Locale.ENGLISH, "Can not find retry exception class %s", className)); diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/config/SpringFactoriesInterceptor.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/config/SpringFactoriesInterceptor.java index 3d5d91e20d..f91f981e02 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/config/SpringFactoriesInterceptor.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/config/SpringFactoriesInterceptor.java @@ -17,6 +17,7 @@ package io.sermant.flowcontrol.config; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor; @@ -101,7 +102,7 @@ private boolean isHasMethodLoadSpringFactories() { private void injectConfigurationsWithLowVersion(Object result, String factoryName) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); if (result instanceof List) { final List convertedResult = (List) result; CLASS_DEFINES.forEach(classInjectDefine -> { @@ -115,7 +116,7 @@ private void injectConfigurationsWithLowVersion(Object result, String factoryNam private void injectConfigurations(Object result) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final boolean isMultiValueMap = result instanceof MultiValueMap; if (result instanceof Map) { // Spring high version processing, for List, which is an immutable list, a layer of processing is required. diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/inject/FlowControlSpringConfigurationInjectDefine.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/inject/FlowControlSpringConfigurationInjectDefine.java index cc34bc8cc1..a12c5b6711 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/inject/FlowControlSpringConfigurationInjectDefine.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/inject/FlowControlSpringConfigurationInjectDefine.java @@ -17,6 +17,7 @@ package io.sermant.flowcontrol.inject; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.service.inject.ClassInjectDefine; import io.sermant.core.utils.ClassUtils; @@ -53,6 +54,8 @@ public Plugin plugin() { } private boolean isLoadedClass(String className) { - return ClassUtils.loadClass(className, Thread.currentThread().getContextClassLoader(), true).isPresent(); + return ClassUtils + .loadClass(className, ClassLoaderManager.getContextClassLoaderOrUserClassLoader(), true) + .isPresent(); } } diff --git a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/retry/ExtensionLoaderInterceptor.java b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/retry/ExtensionLoaderInterceptor.java index bc142cc238..b9010b24f8 100644 --- a/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/retry/ExtensionLoaderInterceptor.java +++ b/sermant-plugins/sermant-flowcontrol/flowcontrol-plugin/src/main/java/io/sermant/flowcontrol/retry/ExtensionLoaderInterceptor.java @@ -17,6 +17,7 @@ package io.sermant.flowcontrol.retry; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.utils.ClassUtils; import io.sermant.flowcontrol.retry.cluster.AlibabaDubboCluster; @@ -70,7 +71,7 @@ protected ExecuteContext doAfter(ExecuteContext context) { return context; } final Optional> retryInvokerClass; - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); if (APACHE_DUBBO_CLUSTER_CLASS_NAME.equals(type.getName())) { ClassUtils.defineClass( "io.sermant.flowcontrol.retry.cluster.ApacheDubboClusterInvoker", contextClassLoader); diff --git a/sermant-plugins/sermant-loadbalancer/dubbo-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/UrlInterceptor.java b/sermant-plugins/sermant-loadbalancer/dubbo-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/UrlInterceptor.java index 515db64b54..5d305d9c43 100644 --- a/sermant-plugins/sermant-loadbalancer/dubbo-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/UrlInterceptor.java +++ b/sermant-plugins/sermant-loadbalancer/dubbo-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/UrlInterceptor.java @@ -17,6 +17,7 @@ package io.sermant.loadbalancer.interceptor; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor; @@ -117,7 +118,7 @@ private void fillSupportRules(String extensionLoaderClazz, String lbClassName) { } supportRules = new HashSet<>(); final Optional> lbClazz = ClassUtils - .loadClass(lbClassName, Thread.currentThread().getContextClassLoader(), true); + .loadClass(lbClassName, ClassLoaderManager.getContextClassLoaderOrUserClassLoader(), true); if (!lbClazz.isPresent()) { return; } @@ -141,7 +142,7 @@ private void fillSupportRules(String extensionLoaderClazz, String lbClassName) { } private boolean isAlibaba() { - return ClassUtils.loadClass(ALIBABA_LOADER, Thread.currentThread().getContextClassLoader(), false) + return ClassUtils.loadClass(ALIBABA_LOADER, ClassLoaderManager.getContextClassLoaderOrUserClassLoader(), false) .isPresent(); } diff --git a/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/io/sermant/loadbalancer/interceptor/SpringFactoriesInterceptor.java b/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/io/sermant/loadbalancer/interceptor/SpringFactoriesInterceptor.java index fd77f73e14..816d7caa7b 100644 --- a/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/io/sermant/loadbalancer/interceptor/SpringFactoriesInterceptor.java +++ b/sermant-plugins/sermant-loadbalancer/loadbalancer-common/src/main/java/io/sermant/loadbalancer/interceptor/SpringFactoriesInterceptor.java @@ -17,6 +17,7 @@ package io.sermant.loadbalancer.interceptor; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor; @@ -101,7 +102,7 @@ private boolean isHasMethodLoadSpringFactories() { private void injectConfigurationsWithLowVersion(Object result, String factoryName) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); if (result instanceof List) { final List convertedResult = (List) result; CLASS_DEFINES.forEach(classInjectDefine -> { @@ -115,7 +116,7 @@ private void injectConfigurationsWithLowVersion(Object result, String factoryNam private void injectConfigurations(Object result) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final boolean isMultiValueMap = result instanceof MultiValueMap; if (result instanceof Map) { // Spring high version processing, for List, which is an immutable list, a layer of processing is required. diff --git a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/RibbonLoadBalancerInterceptor.java b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/RibbonLoadBalancerInterceptor.java index 0e8226e041..b397a8db0d 100644 --- a/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/RibbonLoadBalancerInterceptor.java +++ b/sermant-plugins/sermant-loadbalancer/spring-cloud-loadbalancer-plugin/src/main/java/io/sermant/loadbalancer/interceptor/RibbonLoadBalancerInterceptor.java @@ -21,6 +21,7 @@ import com.netflix.loadbalancer.BaseLoadBalancer; import com.netflix.loadbalancer.IRule; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor; @@ -67,7 +68,7 @@ public class RibbonLoadBalancerInterceptor extends AbstractInterceptor { private final Function> ruleCreator = type -> { final String clazzName = type.getClazzName(); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); try { final Class ruleClazz = contextClassLoader.loadClass(clazzName); return Optional.of((AbstractLoadBalancerRule) ruleClazz.newInstance()); diff --git a/sermant-plugins/sermant-service-registry/dubbo-registry-plugin/src/main/java/io/sermant/dubbo/registry/utils/ReflectUtils.java b/sermant-plugins/sermant-service-registry/dubbo-registry-plugin/src/main/java/io/sermant/dubbo/registry/utils/ReflectUtils.java index 879186fd43..f142ba8b27 100644 --- a/sermant-plugins/sermant-service-registry/dubbo-registry-plugin/src/main/java/io/sermant/dubbo/registry/utils/ReflectUtils.java +++ b/sermant-plugins/sermant-service-registry/dubbo-registry-plugin/src/main/java/io/sermant/dubbo/registry/utils/ReflectUtils.java @@ -16,6 +16,7 @@ package io.sermant.dubbo.registry.utils; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.utils.ClassLoaderUtils; import io.sermant.dubbo.registry.cache.DubboCache; @@ -100,7 +101,7 @@ private ReflectUtils() { * @return Host class */ public static Optional> defineClass(String className) { - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); try { return Optional.of(ClassLoaderUtils.defineClass(className, contextClassLoader, ClassLoaderUtils.getClassResource(ReflectUtils.class.getClassLoader(), className))); diff --git a/sermant-plugins/sermant-service-registry/dubbo-registry-service/src/main/java/io/sermant/dubbo/registry/utils/NamingServiceUtils.java b/sermant-plugins/sermant-service-registry/dubbo-registry-service/src/main/java/io/sermant/dubbo/registry/utils/NamingServiceUtils.java index 767ebbbe92..da08f1ab36 100644 --- a/sermant-plugins/sermant-service-registry/dubbo-registry-service/src/main/java/io/sermant/dubbo/registry/utils/NamingServiceUtils.java +++ b/sermant-plugins/sermant-service-registry/dubbo-registry-service/src/main/java/io/sermant/dubbo/registry/utils/NamingServiceUtils.java @@ -57,7 +57,7 @@ private NamingServiceUtils() { public static NamingService buildNamingService(Map parameters, NacosRegisterConfig registerConfig, RegisterServiceCommonConfig commonConfig) { Properties nacosProperties = buildNacosProperties(parameters, registerConfig, commonConfig); - ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader tempClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); Thread.currentThread().setContextClassLoader(NamingServiceUtils.class.getClassLoader()); try { return NacosFactory.createNamingService(nacosProperties); diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/config/RegistrationProperties.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/config/RegistrationProperties.java index 7a818c57b8..e7fad8ee40 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/config/RegistrationProperties.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/config/RegistrationProperties.java @@ -17,6 +17,7 @@ package io.sermant.registry.config; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.plugin.service.PluginServiceManager; @@ -119,7 +120,7 @@ private Optional tryGetInetUtils() { private Optional tryGetInetUtilsByClazz() { final Optional> clazz = ClassUtils - .loadClass(INET_UTILS_CLASS, Thread.currentThread().getContextClassLoader(), false); + .loadClass(INET_UTILS_CLASS, ClassLoaderManager.getContextClassLoaderOrUserClassLoader(), false); if (!clazz.isPresent()) { return Optional.empty(); } diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/BaseAutoConfigurationDefine.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/BaseAutoConfigurationDefine.java index 8e5c210e73..acb95a9962 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/BaseAutoConfigurationDefine.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/BaseAutoConfigurationDefine.java @@ -17,6 +17,7 @@ package io.sermant.registry.inject; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.service.inject.ClassInjectDefine; import io.sermant.core.utils.ClassUtils; @@ -47,6 +48,7 @@ public Plugin plugin() { * @return Whether it is loaded or not */ protected boolean isClassExistedOnCurrentClassLoader(String className) { - return ClassUtils.loadClass(className, Thread.currentThread().getContextClassLoader(), false).isPresent(); + return ClassUtils.loadClass(className, ClassLoaderManager.getContextClassLoaderOrUserClassLoader(), + false).isPresent(); } } diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/RibbonConfigurationDefine.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/RibbonConfigurationDefine.java index 6322613706..ce35e511cb 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/RibbonConfigurationDefine.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/RibbonConfigurationDefine.java @@ -17,6 +17,7 @@ package io.sermant.registry.inject; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.service.inject.ClassInjectDefine; import io.sermant.core.utils.ClassUtils; @@ -52,6 +53,6 @@ public ClassInjectDefine[] requiredDefines() { public boolean canInject() { return super.canInject() && ClassUtils.loadClass( "org.springframework.cloud.netflix.ribbon.SpringClientFactory", - Thread.currentThread().getContextClassLoader(), false).isPresent(); + ClassLoaderManager.getContextClassLoaderOrUserClassLoader(), false).isPresent(); } } diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/ScServerInjectDefine.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/ScServerInjectDefine.java index b466e46f2c..666572132f 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/ScServerInjectDefine.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/inject/ScServerInjectDefine.java @@ -17,6 +17,7 @@ package io.sermant.registry.inject; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.service.inject.ClassInjectDefine; import io.sermant.core.utils.ClassUtils; @@ -41,7 +42,7 @@ public String factoryName() { @Override public boolean canInject() { - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final RegisterConfig pluginConfig = PluginConfigManager.getPluginConfig(RegisterConfig.class); return pluginConfig.isOpenMigration() && pluginConfig.isEnableSpringRegister() && ClassUtils.loadClass("com.netflix.loadbalancer.Server", contextClassLoader).isPresent(); diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/SpringFactoriesInterceptor.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/SpringFactoriesInterceptor.java index a3624a5131..6927b98a36 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/SpringFactoriesInterceptor.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/SpringFactoriesInterceptor.java @@ -17,6 +17,7 @@ package io.sermant.registry.interceptors; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.plugin.config.PluginConfigManager; @@ -99,7 +100,7 @@ private boolean isHasMethodLoadSpringFactories() { private void injectConfigurationsWithLowVersion(Object result, String factoryName) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); if (result instanceof List) { final List convertedResult = (List) result; CLASS_DEFINES.forEach(classInjectDefine -> { @@ -113,7 +114,7 @@ private void injectConfigurationsWithLowVersion(Object result, String factoryNam private void injectConfigurations(Object result) { final ClassInjectService service = ServiceManager.getService(ClassInjectService.class); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final boolean isMultiValueMap = result instanceof MultiValueMap; if (result instanceof Map) { // Spring is a higher version of the list, and it is an immutable list that needs to be processed at one diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/health/EurekaHealthInterceptor.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/health/EurekaHealthInterceptor.java index 5244222175..c6392b4e19 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/health/EurekaHealthInterceptor.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/interceptors/health/EurekaHealthInterceptor.java @@ -16,6 +16,7 @@ package io.sermant.registry.interceptors.health; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.registry.context.RegisterContext; @@ -40,7 +41,7 @@ protected boolean needCloseRegisterCenter() { @Override protected void close() throws Exception { // Turn off the Eureka timer - final Class discoveryClientClass = Thread.currentThread().getContextClassLoader() + final Class discoveryClientClass = ClassLoaderManager.getContextClassLoaderOrUserClassLoader() .loadClass("com.netflix.discovery.DiscoveryClient"); discoveryClientClass.getDeclaredMethod("shutdown").invoke(target); LOGGER.warning("Eureka register center has been closed by user."); diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/support/InstanceInterceptorSupport.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/support/InstanceInterceptorSupport.java index 5c9b5cc6e3..f001f43397 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/support/InstanceInterceptorSupport.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-plugin/src/main/java/io/sermant/registry/support/InstanceInterceptorSupport.java @@ -17,6 +17,7 @@ package io.sermant.registry.support; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.utils.ClassLoaderUtils; @@ -74,7 +75,7 @@ private RegisterConfig getRegisterConfig() { */ protected final Class getInstanceClass(String className) { return cacheClasses.computeIfAbsent(className, fn -> { - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); Class result = null; try { result = ClassLoaderUtils.defineClass(className, contextClassLoader, diff --git a/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/register/NacosServiceManager.java b/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/register/NacosServiceManager.java index fdb6414d02..48497c6b95 100644 --- a/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/register/NacosServiceManager.java +++ b/sermant-plugins/sermant-service-registry/spring-cloud-registry-service/src/main/java/io/sermant/registry/service/register/NacosServiceManager.java @@ -23,6 +23,7 @@ import com.alibaba.nacos.client.naming.NacosNamingMaintainService; import com.alibaba.nacos.client.naming.NacosNamingService; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.registry.config.ConfigConstants; import io.sermant.registry.config.NacosRegisterConfig; @@ -104,7 +105,7 @@ private void buildNamingService(Properties properties) throws NacosException { } private NamingService createNewNamingService(Properties properties) throws NacosException { - ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader tempClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); try { return new NacosNamingService(properties); @@ -114,7 +115,7 @@ private NamingService createNewNamingService(Properties properties) throws Nacos } private NamingMaintainService createNamingMaintainService(Properties properties) throws NacosException { - ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader(); + ClassLoader tempClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); try { return new NacosNamingMaintainService(properties); diff --git a/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpAsyncClient4xInterceptor.java b/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpAsyncClient4xInterceptor.java index ab528294b2..761f909c43 100644 --- a/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpAsyncClient4xInterceptor.java +++ b/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpAsyncClient4xInterceptor.java @@ -16,6 +16,7 @@ package io.sermant.discovery.interceptors.httpclient; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.plugin.agent.interceptor.Interceptor; import io.sermant.core.plugin.service.PluginServiceManager; @@ -108,7 +109,7 @@ public ExecuteContext after(ExecuteContext context) throws Exception { HttpAsyncUtils.remove(); return context; } - final ClassLoader appClassloader = Thread.currentThread().getContextClassLoader(); + final ClassLoader appClassloader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); try { if (HttpAsyncUtils.getOrCreateContext().getSelectedInstance() != null) { return context; @@ -337,7 +338,7 @@ private HttpRequest rebuildRequest(String uriNew, String method, HttpRequest htt httpPost.setEntity(oldHttpPost.getEntity()); return httpPost; } else { - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final Optional result; try { Thread.currentThread().setContextClassLoader(HttpClient.class.getClassLoader()); diff --git a/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpClient4xInterceptor.java b/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpClient4xInterceptor.java index 57b82c7f74..31cd4febf0 100644 --- a/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpClient4xInterceptor.java +++ b/sermant-plugins/sermant-springboot-registry/springboot-registry-plugin/src/main/java/io/sermant/discovery/interceptors/httpclient/HttpClient4xInterceptor.java @@ -16,6 +16,7 @@ package io.sermant.discovery.interceptors.httpclient; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.agent.entity.ExecuteContext; import io.sermant.core.plugin.service.PluginServiceManager; @@ -92,7 +93,7 @@ public ExecuteContext doBefore(ExecuteContext context) { RequestInterceptorUtils.printRequestLog("HttpClient", hostAndPath); invokerService.invoke( buildInvokerFunc(hostAndPath, httpRequest, context), - buildExFunc(httpRequest, Thread.currentThread().getContextClassLoader()), + buildExFunc(httpRequest, ClassLoaderManager.getContextClassLoaderOrUserClassLoader()), hostAndPath.get(HttpConstants.HTTP_URI_SERVICE)) .ifPresent(result -> this.setResultOrThrow(context, result, hostAndPath.get(HttpConstants.HTTP_URI_PATH))); @@ -111,11 +112,11 @@ private void setResultOrThrow(ExecuteContext context, Object result, String url) private Function buildInvokerFunc(Map hostAndPath, HttpRequest httpRequest, ExecuteContext context) { final String method = httpRequest.getRequestLine().getMethod(); - final ClassLoader appClassloader = Thread.currentThread().getContextClassLoader(); + final ClassLoader appClassloader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); final AtomicReference lastResult = new AtomicReference<>(); return invokerContext -> { tryClose(lastResult.get()); - final ClassLoader pluginClassloader = Thread.currentThread().getContextClassLoader(); + final ClassLoader pluginClassloader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); Thread.currentThread().setContextClassLoader(appClassloader); try { final ServiceInstance serviceInstance = invokerContext.getServiceInstance(); @@ -158,7 +159,7 @@ private Function buildExFunc(HttpRequest httpRequest, ClassLo if (ex instanceof IOException) { return ex; } - final ClassLoader pluginClassloader = Thread.currentThread().getContextClassLoader(); + final ClassLoader pluginClassloader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); Thread.currentThread().setContextClassLoader(appClassloader); try { return new ErrorCloseableHttpResponse(ex, httpRequest.getProtocolVersion()); diff --git a/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/ZkDiscoveryClient.java b/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/ZkDiscoveryClient.java index b0494b1afe..c166c08d67 100644 --- a/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/ZkDiscoveryClient.java +++ b/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/ZkDiscoveryClient.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.plugin.service.PluginServiceManager; @@ -157,7 +158,7 @@ public Collection getInstances(String serviceId) throws QueryIn throw new QueryInstanceException("zk state is not valid!"); } checkDiscoveryState(); - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); try { Thread.currentThread().setContextClassLoader(ZkDiscoveryClient.class.getClassLoader()); return convert(serviceDiscovery.queryForInstances(serviceId)); diff --git a/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/listen/ZkInstanceListenable.java b/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/listen/ZkInstanceListenable.java index 2817c3a3b5..db8d74dfa2 100644 --- a/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/listen/ZkInstanceListenable.java +++ b/sermant-plugins/sermant-springboot-registry/springboot-registry-service/src/main/java/io/sermant/discovery/service/lb/discovery/zk/listen/ZkInstanceListenable.java @@ -16,6 +16,7 @@ package io.sermant.discovery.service.lb.discovery.zk.listen; +import io.sermant.core.classloader.ClassLoaderManager; import io.sermant.core.common.LoggerFactory; import io.sermant.core.plugin.config.PluginConfigManager; import io.sermant.core.plugin.service.PluginServiceManager; @@ -171,7 +172,7 @@ private EventType formatEventType(Type type) { } private Optional deserialize(ChildData childData) { - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final ClassLoader contextClassLoader = ClassLoaderManager.getContextClassLoaderOrUserClassLoader(); try { Thread.currentThread().setContextClassLoader(ZkDiscoveryClient.class.getClassLoader()); final ServiceInstance serviceInstance = serializer.deserialize(childData.getData());