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 87a9f6d4b9..767ebbbe92 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,12 +57,16 @@ private NamingServiceUtils() { public static NamingService buildNamingService(Map parameters, NacosRegisterConfig registerConfig, RegisterServiceCommonConfig commonConfig) { Properties nacosProperties = buildNacosProperties(parameters, registerConfig, commonConfig); + ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(NamingServiceUtils.class.getClassLoader()); try { return NacosFactory.createNamingService(nacosProperties); } catch (NacosException e) { LOGGER.log(Level.SEVERE, String.format(Locale.ENGLISH, "create namingService failed: {%s}", e.getErrMsg()), e); throw new IllegalStateException(e); + } finally { + Thread.currentThread().setContextClassLoader(tempClassLoader); } } 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 792d4182db..fdb6414d02 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 @@ -104,11 +104,23 @@ private void buildNamingService(Properties properties) throws NacosException { } private NamingService createNewNamingService(Properties properties) throws NacosException { - return new NacosNamingService(properties); + ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + try { + return new NacosNamingService(properties); + } finally { + Thread.currentThread().setContextClassLoader(tempClassLoader); + } } private NamingMaintainService createNamingMaintainService(Properties properties) throws NacosException { - return new NacosNamingMaintainService(properties); + ClassLoader tempClassLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + try { + return new NacosNamingMaintainService(properties); + } finally { + Thread.currentThread().setContextClassLoader(tempClassLoader); + } } /**