Native Images Support

从 6.0 版开始, Spring AOT 本机提示支持 Spring Integration 应用程序到本机映像的 GraalVM 编译。对于大多数常见用例,比如带有 @Bean 方法的端点定义、带有 lambda 的 Java DSL 配置和 @MessagingGateway 接口扫描(导入),该框架提供各自的反射、代理和序列化提示。如果配置在 POJO 方法上使用消息传递注解(@ServiceActivator@Splitter 等),或者将 POJO 方法与 IntegrationFlowBuilder.handle(Object service, String methodName) API 一起使用,则还必须使用 @Reflective 注解对其进行标记,因为它们是由框架反射调用。

Starting with version 6.0, GraalVM compilation of Spring Integration applications to native images is supported by Spring AOT native hints. For most common use cases, such as endpoint definitions with @Bean methods, Java DSL configuration with lambdas and @MessagingGateway interface scanning (importing), the framework provides respective reflection, proxy and serialization hints. If configuration uses messaging annotations (@ServiceActivator, @Splitter etc.) on POJO methods, or POJO methods are used with the IntegrationFlowBuilder.handle(Object service, String methodName) API, they have to be also marked with a @Reflective annotation since they are invoked by the framework reflectively.

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

XML configuration is not supported for native images.

如前所述,带有 @MessagingGateway 注释的服务接口在通过 @IntegrationComponentScan 扫描或在 @Import 注释中使用时,会由该框架处理,并将相应的代理提示公开到 AOT 贡献中。当使用 IntegrationFlow.from(Class<?> serviceInterface) API 声明网关时,为这些接口配置的代理必须手动公开:

As stated before, service interfaces with the @MessagingGateway annotation, when they are scanned by the @IntegrationComponentScan or used in an @Import annotation, are processed by the framework and the respective proxy hint is exposed into the AOT contribution. When gateways are declared using the IntegrationFlow.from(Class<?> serviceInterface) API, the proxy configured for such interfaces have to be exposed manually:

@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));
        }

    }

}

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

The IntegrationFlow content is not processed during the AOT processing phase. Therefore, some hints, such as the one mentioned above for a gateway proxy, must be provided by the target application.

当然,配置只是集成解决方案的一部分。最重要的部分是数据通过网络传输以及持久化存储。对于许多用例来说,这是序列化派上用场的地方。Spring 集成将由该框架在内部使用的这些类型的序列化提示公开到原生镜像配置中:StringNumberLongDateArrayListHashMapPropertiesHashtableExceptionUUIDGenericMessageErrorMessageMessageHeadersAdviceMessageMutableMessageMutableMessageHeadersMessageGroupMetadataMessageHolderMessageMetadataMessageHistoryMessageHistory.EntryDelayHandler.DelayedMessageWrapper。对于用户特定数据,通常以消息负载形式存在,必须通过 RuntimeHintsRegistrar 实现手动公开序列化提示,如上面为网关代理所示,还有相应的 RuntimeHints.serialization().registerType() API。

Of course, configuration is just a piece of an integration solution. The most important part is data transferring over the network as well as persistent storage. That’s where serialization comes handy for many use-cases. Spring Integration exposes serialization hints into a native image configuration for these types used by the framework internally: String, Number, Long, Date, ArrayList, HashMap, Properties, Hashtable, Exception, UUID, GenericMessage, ErrorMessage, MessageHeaders, AdviceMessage, MutableMessage, MutableMessageHeaders, MessageGroupMetadata, MessageHolder, MessageMetadata, MessageHistory, MessageHistory.Entry, DelayHandler.DelayedMessageWrapper. For user specific data, mostly present as a message payload, the serialization hint must be exposed manually via a RuntimeHintsRegistrar implementation, as is shown above for a gateway proxy, and the respective RuntimeHints.serialization().registerType() API.

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

It is recommended that native integration applications are developed with Spring Boot, using its respective build tools.