requiredType, Object[] args,
+ boolean typeCheckOnly) throws BeansException {
+
+ T bean = super.doGetBean(name, requiredType, args, typeCheckOnly);
+
+ // 只有是基座isBaseBeanFactory 但获取bean时是模块发起调用(即复用基座的bean时) 记录下复用的基座bean
+ if (isBaseBeanFactory && isOnBiz() && isSingleton(name)) {
+ BASE_FACTORY_REUSE_BEAN_SET.add(bean);
+ }
+
+ return bean;
+ }
+
+ @Override
+ public void destroySingletons() {
+ super.destroySingletons();
+ //复用bean在 基座销毁时清空
+ if (isBaseBeanFactory) {
+ BASE_FACTORY_REUSE_BEAN_SET.clear();
+ }
+ }
+
+ /**
+ * 判断是否需要销毁
+ * 扩展如果是模块上下文且是基座复用的bean 则不需要进行销毁
+ *
+ * @param bean the bean instance to check
+ * @param mbd the corresponding bean definition
+ * @return false 不需要销毁 true 需要销毁
+ */
+ @Override
+ protected boolean requiresDestruction(Object bean, RootBeanDefinition mbd) {
+ //如果是模块上下文且是基座复用的bean 则不需要进行销毁
+ if (!isBaseBeanFactory && isBaseReuseBean(bean)) {
+ //不注册DisposableBean
+ return false;
+ }
+ return super.requiresDestruction(bean, mbd);
+ }
+
+ /**
+ * 是否是基座复用的bean
+ *
+ * @param bean bean 实例
+ * @return true 是 false 不是
+ */
+ private boolean isBaseReuseBean(Object bean) {
+ return BASE_FACTORY_REUSE_BEAN_SET.contains(bean);
+ }
+
+ /**
+ * 判断是否在biz中 而不是基座中
+ *
+ * @return true 在biz中
+ */
+ private boolean isOnBiz() {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ return contextClassLoader == null
+ || BIZ_CLASSLOADER.equals(contextClassLoader.getClass().getName());
+ }
+
+ /**
+ * Getter method for property isBase.
+ *
+ * @return property value of isBase
+ */
+ public boolean isBaseBeanFactory() {
+ return isBaseBeanFactory;
+ }
+
+}
\ No newline at end of file
diff --git a/koupleless-base-plugin/src/main/java/com/alipay/sofa/koupleless/plugin/context/DefaultApplicationContextFactory.java b/koupleless-base-plugin/src/main/java/com/alipay/sofa/koupleless/plugin/context/DefaultApplicationContextFactory.java
new file mode 100644
index 000000000..aeac4f68a
--- /dev/null
+++ b/koupleless-base-plugin/src/main/java/com/alipay/sofa/koupleless/plugin/context/DefaultApplicationContextFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.alipay.sofa.koupleless.plugin.context;
+
+import org.springframework.boot.ApplicationContextFactory;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.core.Ordered;
+
+/**
+ * WebApplicationType.NONE 自定义上下文
+ * 1、基于Spring Boot ApplicationContextFactory SPI扩展 当WebApplicationType.NONE创建一个上下文
+ * 2、仅处理WebApplicationType.NONE 当返回为null时 有其他SPI扩展去处理 即其他ApplicationContextFactory去处理 不同的WebApplicationType
+ * 3、指定 BizDefaultListableBeanFactory{@link com.alipay.sofa.koupleless.plugin.context.BizDefaultListableBeanFactory} 来自定义子模块的销毁行为
+ *
+ * Custom ApplicationContextFactory for WebApplicationType.NONE that uses BizDefaultListableBeanFactory
+ * to prevent destruction of base singleton beans when a module is destroyed.
+ * This factory has the highest precedence and only handles non-web application contexts.
+ *
+ * @author duanzhiqiang
+ * @version DefaultApplicationContextFactory.java, v 0.1 2024年11月12日 17:55 duanzhiqiang
+ */
+public class DefaultApplicationContextFactory implements ApplicationContextFactory, Ordered {
+ @Override
+ public ConfigurableApplicationContext create(WebApplicationType webApplicationType) {
+ return (webApplicationType != WebApplicationType.NONE) ? null
+ : new AnnotationConfigApplicationContext(new BizDefaultListableBeanFactory());
+ }
+
+ @Override
+ public int getOrder() {
+ return Ordered.HIGHEST_PRECEDENCE;
+ }
+}
\ No newline at end of file
diff --git a/koupleless-base-plugin/src/main/resources/META-INF/spring.factories b/koupleless-base-plugin/src/main/resources/META-INF/spring.factories
index 1cda1a4c4..11a982c2b 100644
--- a/koupleless-base-plugin/src/main/resources/META-INF/spring.factories
+++ b/koupleless-base-plugin/src/main/resources/META-INF/spring.factories
@@ -12,4 +12,10 @@ org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\
com.alipay.sofa.koupleless.plugin.spring.SkipAutoConfigurationImportFilter
org.springframework.context.ApplicationContextInitializer=\
- com.alipay.sofa.koupleless.plugin.spring.BizApplicationContextInitializer
\ No newline at end of file
+ com.alipay.sofa.koupleless.plugin.spring.BizApplicationContextInitializer
+
+
+org.springframework.boot.ApplicationContextFactory=\
+com.alipay.sofa.koupleless.plugin.context.BizAnnotationConfigReactiveWebServerApplicationContext.Factory,\
+com.alipay.sofa.koupleless.plugin.context.BizAnnotationConfigServletWebServerApplicationContext.Factory, \
+com.alipay.sofa.koupleless.plugin.context.DefaultApplicationContextFactory
\ No newline at end of file