【问题标题】:JSF 2.3 fails to support WebSocket with Tomcat 9JSF 2.3 无法通过 Tomcat 9 支持 WebSocket
【发布时间】:2018-04-07 22:13:27
【问题描述】:

我尝试使用 JSF 2.3.3(Glassfish 实现)测试新的 WebSocket 功能。我使用 Tomcat 9.0.1 作为 Web 服务器并遵循本指南(https://javaserverfaces.github.io/whats-new-in-jsf23.html)

我创建了一个托管 bean:

@Named
@ApplicationScoped
public class Controller {

    @Inject @Push
    private PushContext cityChannel;

    public void send() {
        cityChannel.send("test");
    }
}

更新了 index.xhtml:

<f:websocket channel="cityChannel"
            onmessage="function(message){alert(message)}" />

并更新了 web.xml:

<context-param>
    <param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
    <param-value>true</param-value>
</context-param>

不幸的是,Tomcat 无法加载应用程序并出现错误:

SEVERE [main] com.sun.faces.config.ConfigureListener.contextInitialized Critical error during deployment:
 javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/javax.faces.push/{channel}] : existing endpoint was [class com.sun.faces.push.WebsocketEndpoint] and new endpoint is [class com.sun.faces.push.WebsocketEndpoint]
        at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:169)

如果我删除上下文参数 javax.faces.ENABLE_WEBSOCKET_ENDPOINT 则 JSF 运行时会在我点击 index.xhtml 时引发错误:

Caused by: java.lang.IllegalStateException: f:websocket endpoint is not enabled. You need to set web.xml context param 'javax.faces.ENABLE_WEBSOCKET_ENDPOINT' with value 'true'.

请指教。

【问题讨论】:

标签: tomcat jsf-2 jsf-2.3


【解决方案1】:

javax.websocket.DeploymentException:多个端点可能不会部署到同一路径 [/javax.faces.push/{channel}]:现有端点是 [class com.sun.faces.push.WebsocketEndpoint] 和新端点是 [class com.sun.faces.push.WebsocketEndpoint] 在 org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:169) 我

当运行时类路径被多个 Mojarra 实现污染时,就会发生这种情况。例如,一个来自jsf-impl.jar 文件,另一个来自javax.faces.jar 文件。甚至可能有多个不同的版本。

您需要确保在运行时类路径中只有一个版本的库。这并不特别适用于 Mojarra,而是适用于每个基于 Java 的库。

Mojarra 的安装说明可以在其README 中找到。

【讨论】:

    猜你喜欢
    • 2020-06-28
    • 2012-07-30
    • 2019-03-03
    • 2017-12-18
    • 1970-01-01
    • 2020-08-31
    • 2019-10-07
    • 1970-01-01
    • 2018-10-10
    相关资源
    最近更新 更多