如何在 Spring 集成路线中集成 Jaxb2Marshaller?

How to integrate the Jaxb2Marshaller in the Spring integration route?

  1. 创建了 Jaxb2Marshaller 对象。
  2. 需要将 java POJO 转换为 XML(编组)。

在集成路由中集成 Jaxb2Marshaller 方面需要帮助。

代码流程:-

@Bean
    public IntegrationFlow flow() throws JAXBException {
        return from(...).
                .enrichHeaders(...)
                .handle(...)
                .transform(processor()::generateXml)
                .channel(...)
                               .get();
    }

如何在 transform() 步骤中添加 Jaxb2Marshaller?

有一个开箱即用的变压器可供使用:

.transform(new MarshallingTransformer(jaxbMarshaller()))

https://docs.spring.io/spring-integration/docs/current/reference/html/xml.html#xml-marshalling-transformer

如何创建Jaxb2Marshaller可以参考Spring框架文档:

https://docs.spring.io/spring/docs/current/spring-framework-reference/data-access.html#oxm-jaxb2