mirror of
https://github.moeyy.xyz/https://github.com/GeWuYou/forgeboot
synced 2025-10-27 13:26:40 +08:00
refactor:优化 Spring 插件代码
- 修改 IsolatedSpringPlugin 和 MergedSpringPlugin 类的注释,提升代码可读性 - 优化 MergedSpringPlugin 类的 createApplicationContext 方法,增加代码注释
This commit is contained in:
parent
2893b5278a
commit
64d25f1683
@ -76,7 +76,7 @@ publish:
|
||||
- echo "🔧 授予 gradlew 执行权限..."
|
||||
- chmod +x gradlew
|
||||
- ./gradlew publishMavenJavaPublicationToGitLabRepository
|
||||
- ./gradlew publishMavenJavaPublicationToGitHubRepository
|
||||
- ./gradlew publishMavenJavaPublicationToGitHubRepository --continue
|
||||
tags:
|
||||
- java
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import org.springframework.context.ApplicationContext
|
||||
/**
|
||||
* 隔离的Spring插件
|
||||
*
|
||||
* 该抽象类继承自SpringPlugin,提供了独立的Spring应用上下文,
|
||||
* 该抽象类继承自AbstractSpringPlugin,提供了独立的Spring应用上下文,
|
||||
* 使得每个插件可以在自己的上下文中管理Bean,实现插件间的隔离。
|
||||
*
|
||||
* @property pluginWrapper 插件包装器,提供插件的基本信息和类加载器
|
||||
|
||||
@ -8,7 +8,7 @@ import org.springframework.core.env.ConfigurableEnvironment
|
||||
/**
|
||||
* 合并的Spring插件
|
||||
*
|
||||
* 该抽象类继承自SpringPlugin,与IsolatedSpringPlugin不同,
|
||||
* 该抽象类继承自AbstractSpringPlugin,与IsolatedSpringPlugin不同,
|
||||
* 它创建的插件应用上下文与主应用上下文建立父子关系,
|
||||
* 使得插件可以访问主应用上下文中的Bean,实现插件与主应用的合并。
|
||||
*
|
||||
@ -24,11 +24,17 @@ abstract class MergedSpringPlugin(
|
||||
*
|
||||
* 创建一个与主应用上下文有关联的 AnnotationConfigApplicationContext,
|
||||
* 设置类加载器、父上下文、环境,并注册插件配置类。
|
||||
*
|
||||
* @return 配置完成的插件应用上下文,与主应用上下文建立了父子关系
|
||||
*/
|
||||
override fun createApplicationContext(): ApplicationContext {
|
||||
// 获取Spring插件管理器
|
||||
val manager = pluginWrapper.pluginManager as SpringPluginManager
|
||||
// 获取父级应用上下文
|
||||
val parentCtx = manager.applicationContext
|
||||
// 获取环境配置
|
||||
val env = parentCtx.environment as ConfigurableEnvironment
|
||||
// 构建插件应用上下文
|
||||
return buildSpringContext(pluginWrapper, parentCtx, env)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user