没有'javax.websocket.server.ServerContainer' ServletContext 属性 - Glassfish 4.1
Posted
技术标签:
【中文标题】没有\'javax.websocket.server.ServerContainer\' ServletContext 属性 - Glassfish 4.1【英文标题】:No 'javax.websocket.server.ServerContainer' ServletContext attribute - Glassfish 4.1没有'javax.websocket.server.ServerContainer' ServletContext 属性 - Glassfish 4.1 【发布时间】:2015-08-18 14:15:18 【问题描述】:我正在使用 Glassfish 4.1 来部署我的 WAR 应用程序。无法连接到 websocket,从 glassfish 收到此消息:
我的 websocket 配置
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry)
registry.addHandler(socketHandler(),"/socket");;
@Bean
public WebSocketHandler socketHandler()
return new WebSocketEndpoint();
WebSocket 处理程序
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
<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】:您应该只有 1.8 版本的 Glassfish Tyrus。放到GlassFish的modules文件夹中(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.tyrus 上找到它们。
这是因为 Spring WebSocket 版本 4.2.1(我有 此版本)取决于 GlassFish Tyrus 1.8 版。
请务必将这些文件放在模块文件夹(glassfish/modules)中,而不是放在那里的文件 tyrus,否则会加载默认 Tyrus。
【讨论】:
我通过在我的运行时配置中添加org.glassfish.tyrus:tyrus-client:1.13.1
依赖项将这些文件放入我的战争中。那也切了。【参考方案2】:
可能你需要添加 javax.websocket 依赖。
马文:
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<scope>provided</scope>
<version>1.1</version>
</dependency>
分级:
'javax.websocket:javax.websocket-api:1.1'
见:https://tyrus.java.net/dependencies.html
【讨论】:
【参考方案3】:我发现可以在您的 POM 文件中包含以下依赖项(我最初从 here 获得信息):
<!-- add the dependency for JSR 356 API -->
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
</dependency>
<!-- add Tyrus JSR 356 implementation related dependencies -->
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-server</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<version>1.12</version>
</dependency>
<!-- add the tyrus-container-grizzly dependency to our pom.xml.
This will provide a standalone container to deploy WebSocket
applications -->
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly</artifactId>
<version>1.2.1</version>
</dependency>
【讨论】:
【参考方案4】:我最近在 tomcat 9(> 9.0.8 版)中运行我的 spring-boot 应用程序时遇到了同样的问题。 是最新版tomcat引入的回归:https://github.com/spring-projects/spring-boot/issues/15746
【讨论】:
以上是关于没有'javax.websocket.server.ServerContainer' ServletContext 属性 - Glassfish 4.1的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot报错:Failed to load ApplicationContext(javax.websocket.server.ServerContainer not available)
html Urusniaga报价模板没有名字,没有电子邮件,没有电话,没有传真。
linux下tomcat启动没有日志,没有进程,没有报错,没有监听端口
为啥 HKSample 数组对于一个没有限制、没有谓词、没有锚点的 HKAnchoredObjectQuery 总是有 1 个值?