diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/client/impl/ClientFactoryImpl.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/client/impl/ClientFactoryImpl.java index 10861432e..5e9660074 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/client/impl/ClientFactoryImpl.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/client/impl/ClientFactoryImpl.java @@ -38,6 +38,11 @@ public void registerClient(Class clientType, Object clientInstance) { clients.put(clientType, clientInstance); } + @Override + public void destroy() { + clients.clear(); + } + @SuppressWarnings("unchecked") @Override public T getClient(Class clazz) { diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/StandardSofaRuntimeManager.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/StandardSofaRuntimeManager.java index ee3ffbff1..3b39dfffc 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/StandardSofaRuntimeManager.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/StandardSofaRuntimeManager.java @@ -129,11 +129,13 @@ public void shutdown() throws ServiceRuntimeException { @Override public void shutDownExternally() throws ServiceRuntimeException { try { + clientFactoryInternal.destroy(); AbstractApplicationContext applicationContext = (AbstractApplicationContext) rootApplicationContext; // only need shutdown when root context is active if (applicationContext.isActive()) { applicationContext.close(); } + rootApplicationContext = null; appClassLoader = null; } catch (Throwable throwable) { throw new ServiceRuntimeException(ErrorCode.convert("01-03100"), throwable); diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/client/ClientFactoryInternal.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/client/ClientFactoryInternal.java index 5bf9e09bd..fe8e68f57 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/client/ClientFactoryInternal.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/client/ClientFactoryInternal.java @@ -31,4 +31,6 @@ public interface ClientFactoryInternal extends ClientFactory { * @param clientInstance client instance */ void registerClient(Class clientType, Object clientInstance); + + void destroy(); }