|
| 1 | +[[native-images-support]] |
| 2 | +=== Native Images Support |
| 3 | + |
| 4 | +Starting with version 6.0, GraalVM compilation of Spring Integration applications to native images is supported by https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aot[Spring AOT] native hints. |
| 5 | +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. |
| 6 | +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. |
| 7 | + |
| 8 | +IMPORTANT: XML configuration is not supported for native images. |
| 9 | + |
| 10 | +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. |
| 11 | +When gateways are declared using the `IntegrationFlow.from(Class<?> serviceInterface)` API, the proxy configured for such interfaces have to be exposed manually: |
| 12 | + |
| 13 | +==== |
| 14 | +[source,java] |
| 15 | +---- |
| 16 | +@Configuration |
| 17 | +@EnableIntegration |
| 18 | +@ImportRuntimeHints(GatewayRuntimeHints.class) |
| 19 | +public class IntegrationConfiguration { |
| 20 | +
|
| 21 | + @Bean |
| 22 | + IntegrationFlow someFlow() { |
| 23 | + return IntegrationFlow.from(SomeGateway) |
| 24 | + // ... |
| 25 | + .get(); |
| 26 | + } |
| 27 | +
|
| 28 | + public interface SomeGateway { |
| 29 | +
|
| 30 | + void doSomething(Object payload); |
| 31 | +
|
| 32 | + } |
| 33 | +
|
| 34 | + private static class GatewayRuntimeHints implements RuntimeHintsRegistrar { |
| 35 | +
|
| 36 | + @Override |
| 37 | + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { |
| 38 | + hints.proxies().registerJdkProxy( |
| 39 | + AopProxyUtils.completeJdkProxyInterfaces(SomeGateway)); |
| 40 | + } |
| 41 | +
|
| 42 | + } |
| 43 | +
|
| 44 | +} |
| 45 | +---- |
| 46 | +==== |
| 47 | + |
| 48 | +NOTE: The `IntegrationFlow` content is not processed during the AOT processing phase. |
| 49 | +Therefore, some hints, such as the one mentioned above for a gateway proxy, must be provided by the target application. |
| 50 | + |
| 51 | +Of course, configuration is just a piece of an integration solution. |
| 52 | +The most important part is data transferring over the network as well as persistent storage. |
| 53 | +That's where serialization comes handy for many use-cases. |
| 54 | +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`. |
| 55 | +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. |
| 56 | + |
| 57 | +NOTE: It is recommended that native integration applications are developed with Spring Boot, using its respective build tools. |
0 commit comments