Spring 4 websocket + Tomcat 7.54 async-supported not working

后端 未结 6 664
名媛妹妹
名媛妹妹 2020-12-19 13:04

I am creating a sample chat application using the Spring websockets and stomp.js , I am using the tomcat 7.54 but while runing the application I am gettting a async-support

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 13:53

    Make sure no other injected component disables async support.


    DETAILS

    I learned that Spring comes with asynchronous support by default.

    And (remotely related) sync logging configuration may disable async handling for entire service.

    Specifically, my logback integration was missing IMPORTANT line:

    public EmbeddedServletContainerCustomizer containerCustomizer(
        final String logbackAccessClasspathConfig
    ) {
        return container -> {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                ((TomcatEmbeddedServletContainerFactory) container)
                    .addContextCustomizers(context -> {
                        LogbackValve logbackValve = new LogbackValve();
                        logbackValve.setFilename(logbackAccessClasspathConfig);
    
                        // IMPORTANT:
                        logbackValve.setAsyncSupported(true);
    
                        context.getPipeline().addValve(logbackValve);
                    }
                );
            }
        };
    }
    

    Thanks to other answer:

    • LogbackValve is configured for synchronous processing by default
    • disable the bean that was injecting LogbackAccess
    • set the asyncSupported="true" attribute where you configure the valve

提交回复
热议问题