当前位置: 首页 > 知识库问答 >
问题:

为Spring Boot驱动的Vaadin应用程序启用服务器推送不起作用

单嘉泽
2023-03-14

在我们当前的项目中,我们希望在Spring Boot的Vaadin应用程序中使用服务器推送。

我们按照维基文章中的说明进行操作https://vaadin.com/book/vaadin7/-/page/advanced.push.html(将vaadin push依赖项添加到pom.xml,将@push注释添加到out UI类,未在web.xml文件中设置支持的异步,因为在本例中它不存在),并收到以下错误消息:

2014-06-17 14:32:43,340 [http-nio-8080-exec-3] WARN  org.atmosphere.cpr.AtmosphereFramework - SessionSupport error. Make sure you define org.atmosphere.cpr.SessionSupport as a listener in web.xml instead
2014-06-17 14:32:44,981 [http-nio-8080-exec-3] WARN  org.atmosphere.cpr.DefaultAsyncSupportResolver - Found multiple containers, please specify which one to use: org.atmosphere.container.Tomcat7CometSupport, org.atmosphere.container.TomcatCometSupport,  until you do, Atmosphere will use:class org.atmosphere.container.Tomcat7CometSupport
2014-06-17 14:32:45,001 [http-nio-8080-exec-3] WARN  org.atmosphere.cpr.AtmosphereFramework - Failed using comet support: org.atmosphere.container.Tomcat7CometSupport, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.You must use the atmosphere-native-runtime dependency in order to use native Comet Support
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat7.jar Is the NIO or APR Connector enabled?
2014-06-17 14:32:45,005 [http-nio-8080-exec-3] ERROR org.atmosphere.cpr.AtmosphereFramework - If you have more than one Connector enabled, make sure they both use the same protocol, e.g NIO/APR or HTTP for all. If not, org.atmosphere.container.BlockingIOCometSupport will be used and cannot be changed.
java.lang.IllegalStateException: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.You must use the atmosphere-native-runtime dependency in order to use native Comet Support
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat7.jar
    at org.atmosphere.container.Tomcat7CometSupport.<clinit>(Tomcat7CometSupport.java:56) ~[atmosphere-runtime-2.1.2.vaadin2.jar:2.1.2.vaadin2]
    (...)
2014-06-17 14:32:45,006 [http-nio-8080-exec-3] WARN  org.atmosphere.cpr.AtmosphereFramework - Using org.atmosphere.container.BlockingIOCometSupport

2014-06-17 14:32:58,684 [http-nio-8080-exec-1] ERROR com.vaadin.server.DefaultErrorHandler - 
java.lang.IllegalStateException: Cannot suspend a response longer than the session timeout. Increase the value of session-timeout in web.xml
    at org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:314) ~[atmosphere-runtime-2.1.2.vaadin2.jar:2.1.2.vaadin2]
    (...)

在阅读stackoverflow线程使用VaadinServlet摆脱Vaadin7中的web.xml后,我们向UI类添加了一个静态servlet

@WebServlet(asyncSupported = true)
public static class Servlet extends VaadinServlet {
}

并收到相同的错误消息:

2014-06-17 14:33:52,928 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.AtmosphereFramework - SessionSupport error. Make sure you define org.atmosphere.cpr.SessionSupport as a listener in web.xml instead
2014-06-17 14:33:54,557 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.DefaultAsyncSupportResolver - Found multiple containers, please specify which one to use: org.atmosphere.container.Tomcat7CometSupport, org.atmosphere.container.TomcatCometSupport,  until you do, Atmosphere will use:class org.atmosphere.container.Tomcat7CometSupport
2014-06-17 14:33:54,577 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.AtmosphereFramework - Failed using comet support: org.atmosphere.container.Tomcat7CometSupport, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.You must use the atmosphere-native-runtime dependency in order to use native Comet Support
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat7.jar Is the NIO or APR Connector enabled?
2014-06-17 14:33:54,581 [http-nio-8080-exec-1] ERROR org.atmosphere.cpr.AtmosphereFramework - If you have more than one Connector enabled, make sure they both use the same protocol, e.g NIO/APR or HTTP for all. If not, org.atmosphere.container.BlockingIOCometSupport will be used and cannot be changed.
java.lang.IllegalStateException: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.You must use the atmosphere-native-runtime dependency in order to use native Comet Support
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat7.jar
    at org.atmosphere.container.Tomcat7CometSupport.<clinit>(Tomcat7CometSupport.java:56) ~[atmosphere-runtime-2.1.2.vaadin2.jar:2.1.2.vaadin2]
   (...)
2014-06-17 14:33:54,582 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.AtmosphereFramework - Using org.atmosphere.container.BlockingIOCometSupport

2014-06-17 14:34:07,338 [http-nio-8080-exec-3] ERROR com.vaadin.server.DefaultErrorHandler - 
java.lang.IllegalStateException: Cannot suspend a response longer than the session timeout. Increase the value of session-timeout in web.xml
    at org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:314) ~[atmosphere-runtime-2.1.2.vaadin2.jar:2.1.2.vaadin2]
    (...)

为会话超时添加参数也不会改变任何内容:

@WebServlet(asyncSupported = true, initParams = { @WebInitParam(name = "session-timeout", value = "120") })
public static class Servlet extends VaadinServlet {
}

2014-06-17 14:36:18,636 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.AtmosphereFramework - SessionSupport error. Make sure you define org.atmosphere.cpr.SessionSupport as a listener in web.xml instead
2014-06-17 14:36:20,284 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.DefaultAsyncSupportResolver - Found multiple containers, please specify which one to use: org.atmosphere.container.Tomcat7CometSupport, org.atmosphere.container.TomcatCometSupport,  until you do, Atmosphere will use:class org.atmosphere.container.Tomcat7CometSupport
2014-06-17 14:36:20,303 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.AtmosphereFramework - Failed using comet support: org.atmosphere.container.Tomcat7CometSupport, error: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.You must use the atmosphere-native-runtime dependency in order to use native Comet Support
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat7.jar Is the NIO or APR Connector enabled?
2014-06-17 14:36:20,307 [http-nio-8080-exec-1] ERROR org.atmosphere.cpr.AtmosphereFramework - If you have more than one Connector enabled, make sure they both use the same protocol, e.g NIO/APR or HTTP for all. If not, org.atmosphere.container.BlockingIOCometSupport will be used and cannot be changed.
java.lang.IllegalStateException: Tomcat failed to detect this is a Comet application because context.xml is missing or the Http11NioProtocol Connector is not enabled.You must use the atmosphere-native-runtime dependency in order to use native Comet Support
If that's not the case, you can also remove META-INF/context.xml and WEB-INF/lib/atmosphere-compat-tomcat7.jar
    at org.atmosphere.container.Tomcat7CometSupport.<clinit>(Tomcat7CometSupport.java:56) ~[atmosphere-runtime-2.1.2.vaadin2.jar:2.1.2.vaadin2]
    (...)
2014-06-17 14:36:20,308 [http-nio-8080-exec-1] WARN  org.atmosphere.cpr.AtmosphereFramework - Using org.atmosphere.container.BlockingIOCometSupport

2014-06-17 14:36:44,341 [http-nio-8080-exec-9] ERROR com.vaadin.server.DefaultErrorHandler - 
java.lang.IllegalStateException: Cannot suspend a response longer than the session timeout. Increase the value of session-timeout in web.xml
    at org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:314) ~[atmosphere-runtime-2.1.2.vaadin2.jar:2.1.2.vaadin2]
    (...)

你有什么解决办法吗?

共有2个答案

夹谷英奕
2023-03-14

在观看了以下Vaadin网络研讨会后,我从服务器推送切换到轮询,这解决了我的问题:

  • http://www.youtube.com/watch?v=GOKX-bGmi0k
  • http://www.youtube.com/watch?v=ZUshNi_4Gqc

以下wiki介绍了如何使用轮询:

https://vaadin.com/wiki/-/wiki/Main/Using投票

姬实
2023-03-14

目前,SpringVaadin仅在未将WEBSOCKET设置为传输模式时才起作用。尝试将其更改为长轮询或流式处理:

@Push(transport = Transport.LONG_POLLING)

就我个人而言,我仍然使用旧的xml配置用于web应用程序。下面是Vaadin 7的推送配置的一部分。

 <!-- Vaadin context -->
<servlet>
    <servlet-name>ISM Application</servlet-name>
    <servlet-class>org.vaadin.spring.servlet.SpringAwareVaadinServlet</servlet-class>
    <init-param>
        <param-name>closeIdleSessions</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:ism-web.xml</param-value>
    </init-param>
    <!-- Vaadin 7.1 @Push -->
    <init-param>
        <param-name>org.atmosphere.useWebSocketAndServlet3</param-name>
        <param-value>true</param-value>
    </init-param>
    <async-supported>true</async-supported>
</servlet>
 类似资料:
  • 在尝试运行Spring Temple项目时收到此错误消息不知道为什么?有什么建议吗? 这是来自控制台的完整日志 我对代码进行了任何修改,只是试图运行从Spring模板下载的应用程序

  • 我是Apache Kafka的新手,我试图从windows机器上运行.\bin\windows\kafka-server-start.bat.\config\server.properties命令来启动Kafka服务器,但我没有得到命令提示符屏幕的任何响应,既没有任何错误消息,也没有任何成功消息,它只是把我扔到了一个新的命令行。虽然我能够成功运行Zookeeper服务器。我已经正确地更新了serv

  • “C:\程序文件\SimpleNode\nssm.exe”安装SimpleNode“C:\程序文件\SimpleNode\node.exe”C:\程序文件\SimpleNode\simple.js“ 服务已安装。当我启动它时,我得到一条错误消息,服务处于暂停状态,我在事件查看器中看到以下错误: GetProcessTimes()失败:句柄无效。

  • 我正在设置micronaut应用程序,但部署失败,出现以下异常: 我们有3个环境:开发,测试和生产。它在开发和测试中工作,但不在生产中。我们验证了环境变量和jdk版本。我们在云环境中,相同的映像正在部署在开发、测试和生产中。 NA

  • 我正在尝试开发一个HTML5应用程序,通过PhoneGap移植到native。该应用程序是否可以在移动设备上充当服务器,在另一个移动设备上充当客户端并连接到前者?这些都在本地网络中。 我是PhoneGap的新手,我知道大多数服务器实现都在node.js或PHP等平台上,而且PhoneGap只支持超文本标记语言、CSS和JavaScript。我认为我在这里可能部分错误,因为有各种插件可以帮助简化Ph

  • 使用spring-boot时,一切工作都很好。尽管如此,在spring-boot中已删除了注释和。我试图将代码重构为新版本,但我做不到。对于以下测试,我的应用程序在测试之前没有启动,http://localhost:8080返回404: 如何重构测试以使其在Spring-Boot1.5中工作?