|
如需使用最新稳定版本,请使用 Spring Integration 7.0.4! |
原生图像支持
从版本 6.0 开始,Spring AOT1原生提示支持将 Spring Integration 应用程序编译为 GraalVM 原生镜像。
对于大多数常见用例,例如使用@MessagingGateway方法定义端点、使用 Lambda 的 Java DSL 配置以及@ServiceActivator接口扫描(导入),框架提供了相应的反射、代理和序列化提示。
如果配置在 POJO 方法上使用了消息注解(如@Splitter、IntegrationFlowBuilder.handle(Object service, String methodName)等),或者 POJO 方法与@Reflective API 一起使用,则由于这些方法是通过反射由框架调用的,因此还必须用7注解进行标记。
| 原生镜像不支持 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));
}
}
}
IntegrationFlow 的内容在 AOT 处理阶段不会被处理。
因此,某些提示(例如上述关于网关代理的提示)必须由目标应用程序提供。 |
当然,配置只是集成解决方案的一部分。
最重要的部分是通过网络传输数据以及持久化存储。
这就是序列化在许多用例中派上用场的地方。
Spring Integration 将这些框架内部使用的类型(String, Number, Long, Date, ArrayList, HashMap, Properties, Hashtable, Exception, UUID, GenericMessage, ErrorMessage, MessageHeaders, AdviceMessage, MutableMessage, MutableMessageHeaders, MessageGroupMetadata, MessageHolder, MessageMetadata, MessageHistory, MessageHistory.Entry, DelayHandler.DelayedMessageWrapper)的序列化提示暴露到原生镜像配置中:
对于用户特定的数据(通常作为消息负载存在),序列化提示必须通过 RuntimeHintsRegistrar 实现手动暴露,正如上述网关代理所示,以及相应的 RuntimeHints.serialization().registerType() API。
| 建议使用 Spring Boot 及其相应的构建工具来开发原生集成应用程序。 |