首页 > 解决方案 > MarshallingWebServiceOutboundGateway 第一次请求占用太多

问题描述

我们有很多可以用来连接的soap服务,每次第一次连接到同一个服务都需要花费大量时间从集成开始,随后的请求会迅速减少60%的响应时间。

解析JAXB绑定初始化

@Configuration
public interface WSCommons {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    @Bean
      static Jaxb2Marshaller jaxb2Marshaller() {
            marshaller.setPackagesToScan("com.abc");
        return marshaller;
      }
}

这需要大量的第一个请求来扫描所有内容并创建编组器。

但,

一旦 Bean 被初始化,它就可以快速处理少量请求。当服务流空闲一段时间并且请求再次开始流动时,MarshallingWebServiceOutboundGateway 滞后非常糟糕。

Jaxb2Marshaller 是静态的,在这种情况下它应该停止重新初始化。

任何输入表示赞赏,可能在初始化时做错了。

谢谢

标签: spring-integrationspring-integration-dslspring-integration-http

解决方案


我不相信它会@Configuration在界面上使用。因此,您的@BeanforJaxb2Marshaller是不可见的。

您需要考虑将您的 @Configuration设置为 aclass并将其static从 bean 定义中删除。

Jaxb2Marshaller一个选项,如:

/**
 * Set whether to lazily initialize the {@link JAXBContext} for this marshaller.
 * Default is {@code false} to initialize on startup; can be switched to {@code true}.
 * <p>Early initialization just applies if {@link #afterPropertiesSet()} is called.
 */
public void setLazyInit(boolean lazyInit) {

这是false默认情况下,因此afterPropertiesSet()在正常的 bean 初始化阶段调用。所有的包都在这里扫描,一个完整的包JAXBContext被缓存在Jaxb2Marshallerbean 中。


推荐阅读