原生映像檔支援
從 6.0 版本開始,Spring Integration 應用程式編譯為原生映像檔的功能,已透過 Spring AOT 原生提示獲得支援。對於最常見的使用案例,例如使用 @Bean
方法的端點定義、使用 lambda 的 Java DSL 設定,以及 @MessagingGateway
介面掃描(匯入),框架會提供各自的反射、代理和序列化提示。如果設定在 POJO 方法上使用訊息傳遞註解(@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 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 及其各自的建置工具進行開發。 |