From 7f083a943373da1880ae617437e1179c6ccbe837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BB=98?= <925456043@qq.com> Date: Thu, 20 Aug 2026 11:24:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=98=8E=E7=A1=AE=20Skill=20Git=20?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E7=AD=96=E7=95=A5=E6=B3=A8=E5=85=A5=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 标记生产构造器供 Spring 容器稳定选择 - 补充组件实例化回归测试 --- .../gitimport/GitRepositoryAccessPolicy.java | 8 ++++++++ .../gitimport/GitRepositoryAccessPolicyTest.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/easyflow-modules/easyflow-module-skill/src/main/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicy.java b/easyflow-modules/easyflow-module-skill/src/main/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicy.java index f4e5b618..321e88ca 100644 --- a/easyflow-modules/easyflow-module-skill/src/main/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicy.java +++ b/easyflow-modules/easyflow-module-skill/src/main/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicy.java @@ -1,5 +1,6 @@ package tech.easyflow.skill.gitimport; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import tech.easyflow.common.web.exceptions.BusinessException; @@ -28,10 +29,17 @@ public class GitRepositoryAccessPolicy { * * @param properties Git 导入配置 */ + @Autowired public GitRepositoryAccessPolicy(SkillGitImportProperties properties) { this(properties, InetAddress::getAllByName); } + /** + * 创建可替换主机解析器的 Git 地址访问策略。 + * + * @param properties Git 导入配置 + * @param hostResolver 主机解析器 + */ GitRepositoryAccessPolicy(SkillGitImportProperties properties, HostResolver hostResolver) { this.properties = properties; this.hostResolver = hostResolver; diff --git a/easyflow-modules/easyflow-module-skill/src/test/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicyTest.java b/easyflow-modules/easyflow-module-skill/src/test/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicyTest.java index 7d1ec262..94142ba3 100644 --- a/easyflow-modules/easyflow-module-skill/src/test/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicyTest.java +++ b/easyflow-modules/easyflow-module-skill/src/test/java/tech/easyflow/skill/gitimport/GitRepositoryAccessPolicyTest.java @@ -2,6 +2,7 @@ package tech.easyflow.skill.gitimport; import org.junit.Before; import org.junit.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; import tech.easyflow.common.web.exceptions.BusinessException; import java.io.IOException; @@ -11,6 +12,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.Set; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; /** @@ -30,6 +32,20 @@ public class GitRepositoryAccessPolicyTest { policy = new GitRepositoryAccessPolicy(properties); } + /** + * Spring 容器应选择生产构造器完成组件实例化。 + */ + @Test + public void springContextUsesProductionConstructor() { + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { + context.registerBean(SkillGitImportProperties.class, SkillGitImportProperties::new); + context.register(GitRepositoryAccessPolicy.class); + context.refresh(); + + assertNotNull(context.getBean(GitRepositoryAccessPolicy.class)); + } + } + /** * 仓库地址允许省略 .git 后缀并移除结尾斜线。 */