fix(design): @Autowired DesignFeatureController 生产构造器 — 修 Spring 多构造器回退无参导致启动崩
live e2e 揪出:DesignFeatureController 有「生产构造+包级测试构造」两个构造器, 生产构造未标 @Autowired → Spring 回退找无参构造 → NoSuchMethodException 启动失败。 纯单元测试全 new 对象故漏检;真实 boot 才暴露。补 @Autowired + 回归测试守护此装配模式。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package com.eip4.platform.metadata.web;
|
package com.eip4.platform.metadata.web;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -60,6 +62,7 @@ public class DesignFeatureController {
|
|||||||
private final com.eip4.platform.metadata.publish.PublishOrchestrator publishOrchestrator; // Task 11-13
|
private final com.eip4.platform.metadata.publish.PublishOrchestrator publishOrchestrator; // Task 11-13
|
||||||
|
|
||||||
/** 生产构造(Spring 注入)。 */
|
/** 生产构造(Spring 注入)。 */
|
||||||
|
@Autowired
|
||||||
public DesignFeatureController(JdbcTemplate jdbcTemplate,
|
public DesignFeatureController(JdbcTemplate jdbcTemplate,
|
||||||
PageSchemaWriter pageSchemaWriter,
|
PageSchemaWriter pageSchemaWriter,
|
||||||
EntityAttributeReader attributeReader,
|
EntityAttributeReader attributeReader,
|
||||||
|
|||||||
@@ -74,4 +74,16 @@ class DesignFeatureControllerTest {
|
|||||||
ResponseEntity<Map<String, Object>> resp = controller(writer, reader).compile(body);
|
ResponseEntity<Map<String, Object>> resp = controller(writer, reader).compile(body);
|
||||||
assertEquals(400, resp.getStatusCode().value());
|
assertEquals(400, resp.getStatusCode().value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("3. 装配回归:有两个构造器时,生产构造器必须 @Autowired,否则 Spring 回退无参构造启动崩(live e2e 揪出)")
|
||||||
|
void productionConstructorIsAutowired() {
|
||||||
|
// 本控制器同时有「生产构造」与「包级测试构造」两个构造器。
|
||||||
|
// Spring 对多构造器类必须靠 @Autowired 指定注入构造,否则找无参构造 → NoSuchMethodException 启动失败。
|
||||||
|
long autowired = java.util.Arrays.stream(DesignFeatureController.class.getDeclaredConstructors())
|
||||||
|
.filter(c -> c.isAnnotationPresent(org.springframework.beans.factory.annotation.Autowired.class))
|
||||||
|
.count();
|
||||||
|
assertEquals(1, autowired,
|
||||||
|
"DesignFeatureController 有多个构造器,生产构造器必须且仅一个标 @Autowired");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user