对于最新的稳定版本,请使用 Spring Integration 6.4.0! |
本机映像支持
从版本 6.0 开始,Spring AOT 原生提示支持将 Spring 集成应用程序编译为原生镜像的 GraalVM。
对于大多数常见的使用案例,例如使用@Bean
方法、使用 lambda 的 Java DSL 配置以及@MessagingGateway
接口扫描 (importing) 时,框架会提供相应的 Reflection、Proxy 和 Serialization Hint。
如果配置使用消息传递注释 (@ServiceActivator
,@Splitter
等)或 POJO 方法与IntegrationFlowBuilder.handle(Object service, String methodName)
API 时,它们还必须标有@Reflective
注解,因为它们是由框架反射式调用的。
本机映像不支持 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 集成将序列化提示公开到框架内部使用的这些类型的本机图像配置中: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()
应用程序接口。
建议使用 Spring Boot 使用其各自的构建工具开发本机集成应用程序。 |