本文介绍了没有'javax.websocket.server.ServerContainer' ServletContext 属性 - Glassfish 4.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Glassfish 4.1 来部署我的 WAR 应用程序.无法连接到 websocket,从 glassfish 收到此消息:

I'm using Glassfish 4.1 to deploy my WAR application. Cannot connect to websocket, getting this message from glassfish:

我的 websocket 配置

My websocket configuration

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(socketHandler(),"/socket");;
    }

    @Bean
    public WebSocketHandler socketHandler() {
        return new WebSocketEndpoint();
    }


}

WebSocket 处理程序

WebSocket Handler

public class WebSocketEndpoint extends TextWebSocketHandler {

    @Autowired
    private TestService testService;

    @Override
    public void handleTextMessage(WebSocketSession session, TextMessage message) {
        System.out.println("Testing "+message.getPayload());
        try {
            session.sendMessage(new TextMessage(testService.getWelcomeMessage()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

我的 dispatcher-servlet 中有一个 bean

And I got a bean in my dispatcher-servlet

<bean class="pl.iaserver.websocket.WebSocketConfig"/>

错误:

ava.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getContainer(AbstractStandardUpgradeStrategy.java:68)
    at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getSupportedExtensions(AbstractStandardUpgradeStrategy.java:88)
    at org.springframework.web.socket.server.support.DefaultHandshakeHandler.doHandshake(DefaultHandshakeHandler.java:209)
    at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:128)
    at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
]]

推荐答案

你应该只有 1.8 版本的 Glassfish Tyrus.放到GlassFish的modules文件夹中(glassfish/modules).

You should have Glassfish Tyrus of 1.8 version only. Put it in the modules folder of GlassFish (glassfish/modules).

  • tyrus-core-1.8.jar
  • tyrus-client-1.8.jar
  • tyrus-container-glassfish-cdi-1.8.jar
  • tyrus-container-glassfish-ejb-1.8.jar
  • tyrus-container-grizzly-client-1.8.jar
  • tyrus-container-servlet-1.8.jar
  • tyrus-server-1.8.jar
  • tyrus-spi-1.8.jar

您可以在 http://mvnrepository.com/artifact/org.glassfish 上找到它们.酪梨.

这是因为 Spring WebSocket 版本 4.2.1(我有此版本)依赖于 GlassFish Tyrus 1.8 版.

The reason for this is because Spring WebSocket version 4.2.1 (I havethis version) depends on GlassFish Tyrus version 1.8.

请务必将这些文件放在模块文件夹(glassfish/modules)中,而不是将文件 tyrus 放在那里,否则会加载默认 Tyrus.

Be sure to put these files in the modules folder (glassfish/modules) instead of the files tyrus lying there, otherwise Default Tyrus will be loaded.

这篇关于没有'javax.websocket.server.ServerContainer' ServletContext 属性 - Glassfish 4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 03:14