fix: 修复插件启动失败——移除 ObjectMapper bean 注入
真实 Halo 2.26.1(Spring Boot 4)插件上下文中不存在 com.fasterxml.jackson.databind.ObjectMapper bean(错误截图: ChangeCaptureManager 构造参数 3 UnsatisfiedDependency)。 改为使用 Halo API 自带的 Unstructured.OBJECT_MAPPER(Jackson 2, 与 diff 引擎的 JsonNode 类型一致),本地测试未暴露此问题, 因单测从不启动插件 Spring 上下文。
This commit is contained in:
+3
-3
@@ -5,7 +5,6 @@ import static run.halo.operationaudit.audit.CaptureRule.WRITE_METHODS;
|
||||
import static run.halo.operationaudit.audit.CaptureRule.isAuthEndpoint;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
@@ -48,7 +47,6 @@ public class ChangeCaptureManager {
|
||||
private final AuditSettingProvider settingProvider;
|
||||
private final SchemeManager schemeManager;
|
||||
private final ReactiveExtensionClient client;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* 捕获变更上下文,返回(可能包装了缓存请求体的)交换对象供后续链路继续处理。
|
||||
@@ -138,8 +136,10 @@ public class ChangeCaptureManager {
|
||||
}
|
||||
|
||||
private JsonNode parseJson(byte[] bytes) {
|
||||
// 用 Halo 提供的 Unstructured 静态 mapper(Jackson 2,与 diff 树类型一致),
|
||||
// 不注入 ObjectMapper bean:插件上下文(Spring Boot 4)中无该类型
|
||||
try {
|
||||
return objectMapper.readTree(bytes);
|
||||
return Unstructured.OBJECT_MAPPER.readTree(bytes);
|
||||
} catch (java.io.IOException e) {
|
||||
// 非 JSON 内容或超限(StreamReadConstraints):不记字段变更,不影响记录
|
||||
return null;
|
||||
|
||||
+1
-4
@@ -9,7 +9,6 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -35,8 +34,6 @@ import run.halo.operationaudit.housekeeping.AuditSettings;
|
||||
*/
|
||||
class ChangeCaptureManagerTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private AuditSettingProvider settingProvider;
|
||||
private SchemeManager schemeManager;
|
||||
private ReactiveExtensionClient client;
|
||||
@@ -53,7 +50,7 @@ class ChangeCaptureManagerTest {
|
||||
settingProvider = mock(AuditSettingProvider.class);
|
||||
schemeManager = mock(SchemeManager.class);
|
||||
client = mock(ReactiveExtensionClient.class);
|
||||
manager = new ChangeCaptureManager(settingProvider, schemeManager, client, MAPPER);
|
||||
manager = new ChangeCaptureManager(settingProvider, schemeManager, client);
|
||||
targetScheme = Scheme.buildFromType(AuditLog.class);
|
||||
when(schemeManager.schemes()).thenReturn(java.util.List.of(targetScheme));
|
||||
when(settingProvider.get()).thenReturn(Mono.just(AuditSettings.defaults()));
|
||||
|
||||
Reference in New Issue
Block a user