跳到主要内容

原生图像支持

QWen Plus 中英对照 Native Images Support

从 6.0 版本开始,GraalVM 编译 Spring Integration 应用程序为原生镜像由 Spring AOT 原生提示支持。对于大多数常见用例,例如带有 @Bean 方法的端点定义、使用 lambda 的 Java DSL 配置和 @MessagingGateway 接口扫描(导入),框架提供了相应的反射、代理和序列化提示。如果配置使用了消息注解 (@ServiceActivator, @Splitter 等) 在 POJO 方法上,或者 POJO 方法是通过 IntegrationFlowBuilder.handle(Object service, String methodName) API 使用的,由于它们是由框架反射调用的,因此也必须标记为 @Reflective 注解。

important

不支持原生镜像的 XML 配置。

如前所述,带有 @MessagingGateway 注解的服务接口,在被 @IntegrationComponentScan 扫描或在 @Import 注解中使用时,会被框架处理,并将相应的代理提示暴露给 AOT 贡献。当使用 IntegrationFlow.from(Class<?> serviceInterface) API 声明网关时,必须手动暴露为此类接口配置的代理:

@Configuration
@EnableIntegration
@ImportRuntimeHints(GatewayRuntimeHints.class)
public class IntegrationConfiguration {

@Bean
IntegrationFlow someFlow() {
return IntegrationFlow.from(SomeGateway)
// ...
.get();
}

public interface SomeGateway {

void doSomething(Object payload);

}

private static class GatewayRuntimeHints implements RuntimeHintsRegistrar {

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.proxies().registerJdkProxy(
AopProxyUtils.completeJdkProxyInterfaces(SomeGateway));
}

}

}
java
备注

IntegrationFlow 内容在 AOT 处理阶段不会被处理。因此,某些提示(例如上面提到的网关代理提示)必须由目标应用程序提供。

当然,配置只是集成解决方案的一部分。最重要的是数据在网络中的传输以及持久化存储。这就是为什么序列化在许多用例中非常有用。Spring Integration 为框架内部使用的这些类型暴露了序列化提示到原生镜像配置中:StringNumberLongDateArrayListHashMapPropertiesHashtableExceptionUUIDGenericMessageErrorMessageMessageHeadersAdviceMessageMutableMessageMutableMessageHeadersMessageGroupMetadataMessageHolderMessageMetadataMessageHistoryMessageHistory.EntryDelayHandler.DelayedMessageWrapper。对于用户特定的数据,通常作为消息有效负载出现,必须通过 RuntimeHintsRegistrar 实现手动暴露序列化提示,就像上面为网关代理所示的那样,以及相应的 RuntimeHints.serialization().registerType() API。

备注

建议使用 Spring Boot 及其各自的构建工具开发原生集成应用程序。