【问题标题】:MarshallingWebServiceOutboundGateway takes too much for the first requestMarshallingWebServiceOutboundGateway 第一次请求占用太多
【发布时间】:2018-10-08 20:00:30
【问题描述】:

我们有 很多 用于连接的 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-integration spring-integration-dsl spring-integration-http


    【解决方案1】:

    我不相信它会与界面上的@Configuration 一起工作。因此,Jaxb2Marshaller@Bean 不可见。

    您需要考虑将您的 @Configuration 设为 class 并从 bean 定义中删除该 static

    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,因此在正常的bean初始化阶段调用afterPropertiesSet()。所有的包都在这里扫描,一个完整的JAXBContext缓存在Jaxb2Marshaller bean中。

    【讨论】:

    • 我实际上有这个问题,如果每次创建请求并打开网关时都会创建上下文。有一个调试点:private JAXBContext createJaxbContextFromPackages() throws JAXBException 它只在第一个请求时停止一次,随后就没有了。
    • 通过代码工作,它只是在 SOAP 流上很慢。我正在检查是否没有正确创建或检索 JAXB 上下文。
    • 我不确定你在说什么。只有我在您提供的配置中看到的,您使用 Spring 的方式是错误的。你的问题中遗漏了所有的休息。所以,这可能只是一个猜测
    • 太多不相关的信息。我打算以Not clear what you’re asking 结束您的问题
    • 将发布一个新问题
    猜你喜欢
    • 2015-07-21
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-31
    • 2021-07-15
    相关资源
    最近更新 更多