java - 将 WebContextHandler 设置为 jetty 服务器失败

标签 java jetty

我尝试将 WebAppContext 设置为 Jetty 服务器处理程序,但在 server.setHandler() 调用时失败。异常时给出以下消息。任何帮助将不胜感激。

org.eclipse.jetty.servlet.ServletContextHandler。(Lorg/eclipse/jetty/server/HandlerContainer;Ljava/lang/String;Lorg/eclipse/jetty/server/session/SessionHandler;Lorg/eclipse/jetty/security/SecurityHandler;Lorg/eclipse/jetty/servlet/ServletHandler;Lorg/eclipse/jetty/server/handler/ErrorHandler;I)V

WebAppContext webAppContext = new WebAppContext("samples/webapp", "/");
    webAppContext.setConfigurationClasses(new String[]{
            "org.eclipse.jetty.webapp.WebInfConfiguration",
            "org.eclipse.jetty.webapp.WebXmlConfiguration"});        
Server server = new Server(port);
server.setHandler(webAppContext);
server.start();

我使用的是jetty版本9.2.16.v20160414。提前致谢。

已解决: 现在这个问题已经解决了。存在依赖冲突

最佳答案

完全删除 setConfigurationClasses() 调用,并使用默认值。

您拥有的代码取消了 Web 应用程序的大部分 servlet 级别要求,使 Web 应用程序的大约 80% 的功能无效。

虽然可以使用少于默认的 webapp 配置类来运行,但这种操作是非常高级的用法。不要尝试删除默认的配置类,除非您非常了解自己在做什么,并且首先了解所有现有配置类的作用。

如果您在网络上看到执行此操作的代码,请避免使用它(暂时)。

话虽如此,如果您看到添加默认配置类的代码,这是正常的。

Note: Jetty is highly modular, and you can setup/tweak environments to some truely stunning modes. Once you start digging into Jetty, you'll see that nothing is required, not even the Server!

This modular nature is unique the world of Java Web Servers, and is the source of much confusion for folks familiar with other servers. The expectations that it "just work" is true, but only in the context of defined defaults. The more you move away from the defaults, the more work you have to do yourself.

关于java - 将 WebContextHandler 设置为 jetty 服务器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37790156/

相关文章:

Java wordsearch 字符数组

jsp - 如何让嵌入的 Jetty 9 成功解析 JSTL URI?

java - 使用 Spring-Boot 和 Jetty 设置 SSL

mysql - 在 Solr 中创建两个使用相同模式的实例的最佳方法是什么?

java - 如何从 servlet 中获取 org.eclipse.jetty.server.Request

java - 实现 AbstractMultiTenantConnectionProvider

java - 使用 OkHttp 3 发送原始 POST 请求

java - Jhipster CORS 启用

java - Java 中的模式比较技术

java - 意外响应 408 登录 cometd 客户端