【问题标题】:Using wars in jetty embedded, websocket getting no factory for upgrade在 jetty 嵌入式中使用战争,websocket 无法升级
【发布时间】:2020-09-09 15:36:44
【问题描述】:

我有两场战争,我试图在码头嵌入式 uberjar 中运行。其中之一使用 websockets。使用浏览器,除了 websockets 之外,我可以很好地获得两场战争的响应。当我将日志记录级别降至调试时,我看到以下错误。是否有我没有在我的 WebAppContexts 上配置的工厂?

2020-09-09 10:35:10.204:DBUG:oejs.HttpChannelOverHttp:qtp38997010-16:升级 HttpChannelOverHttp@3627c323{s=HttpChannelState@42e23fe6{s=IDLE rs=BLOCKING os=OPEN is=IDLE awp=false se=false i=true al=0},r=0,c=false/false,a=IDLE,uri=null,age=0} 升级:websocket 2020-09-09 10:35:10.204:DBUG:oejs.HttpChannelOverHttp:qtp38997010-16:无升级工厂:ServerConnector@6073f712{HTTP/1.1, (http/1.1)}{0.0.0.0:9191}

来源:

    public static void main(String[] args) throws Exception {
        Server server = new Server();
        ServerConnector connector = new ServerConnector(server);
        server.setConnectors(new Connector[]{connector});
        
        // war #1
        WebAppContext portalContext = new WebAppContext();
        portalContext.setContextPath("/portal");
        portalContext.setWar("/path/to/war/file/app1.war")
    
        // war #2 (war with websocket)
        WebAppContext hubContext = new WebAppContext();
        hubContext.setContextPath("/hub");
        hubContext.setWar("/path/to/war/file/app2.war")
    
        HandlerCollection handlerCollection = new HandlerCollection();
        handlerCollection.setHandlers(new Handler[]{hubContext, portalContext});
        server.setHandler(handlerCollection);
    
        try {
            server.start();
            System.in.read();
            server.stop();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(100);
        }
    }

【问题讨论】:

  • 请编辑您的问题并包含有关您如何为这些war 文件创建(和配置)WebAppContext 的代码sn-p。您似乎缺少一些 Configuration 类型和/或字节码扫描。
  • 更新了正在使用的源代码。

标签: websocket jetty war


【解决方案1】:

在服务器级别启用字节码扫描。

Server server = new Server();
Configuration.ClassList classlist = Configuration.ClassList
    .setServerDefault(server);

classlist.addBefore(
    "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
    "org.eclipse.jetty.annotations.AnnotationConfiguration");

这会将 AnnotationConfiguration 应用到所有已部署的 WebAppContexts。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 2014-05-11
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    相关资源
    最近更新 更多