【问题标题】:Spring - Websockets - JSR-356Spring - Websockets - JSR-356
【发布时间】:2020-12-29 14:04:40
【问题描述】:

我在我的应用程序中实现了 websocket。我从 jHipster 生成的应用程序中复制了配置和依赖项,但出现以下错误:

java.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?

org.apache.catalina.connector.ClientAbortException: java.io.IOException: An established connection was aborted by the software in your host machine

我相信这些错误是套接字连接不一致的原因,因此客户端无法发送和/或接收任何消息。 我搜索了一个解决方案,但其他帖子没有帮助(即添加 glassfish 依赖项)。

这些是我的 ws 依赖项:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-messaging</artifactId>
        </dependency>

我需要包含一些其他依赖项还是其他地方的问题?

【问题讨论】:

    标签: spring spring-boot jhipster spring-websocket


    【解决方案1】:

    我找到了解决方案here。 我添加了这 2 个 bean:

        @Bean
        public TomcatServletWebServerFactory tomcatContainerFactory() {
            TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();;
            factory.setTomcatContextCustomizers(Collections.singletonList(tomcatContextCustomizer()));
            return factory;
        }
    
        @Bean
        public TomcatContextCustomizer tomcatContextCustomizer() {
            return new TomcatContextCustomizer() {
                @Override
                public void customize(Context context) {
                    context.addServletContainerInitializer(new WsSci(), null);
                }
            };
        }
    

    【讨论】:

      猜你喜欢
      • 2016-03-18
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      相关资源
      最近更新 更多