首页 > 解决方案 > Embedded Jetty 无法获取我的资源文件

问题描述

我正在使用带有 webAppContext 的嵌入式 Jetty 的 SNI。在大多数情况下,这工作正常。我已经切换到 Jetty 的 9.4.8 版本。

该服务在 SNI 方面启动得很好,并正确加载所有内容并读取所有证书。但是,当我从多个浏览器发出特定请求时,这些浏览器在我的资源路径上涉及 JS 和图像文件,浏览器抱怨没有GET为这些文件定义,但引用/获取使用@RequestMapping.

以下代码在以前版本的 Jetty 中运行良好,但现在无法运行。Jetty 9.4.8 是否改变了解析相对引用的方式。

任何想法将不胜感激。


码头代码(到目前为止,这已经工作了多年)

 WebAppContext webAppContext = new WebAppContext();
        Resource webappDir = Resource.newResource(System.getProperty("traffic.app.dir"));
        webAppContext.setBaseResource(webappDir);
        webAppContext.setDescriptor("WEB-INF/web.xml");
        webAppContext.setContextPath("/");
        webAppContext.setParentLoaderPriority(false);
        webAppContext.setLogUrlOnStart(true);

现在失败的html片段是

<script type="text/javascript" src="/js/spin.js"></script>

资源路径在哪里file:///f/f2-traffic/webapp/

错误是

Loading failed for the <script> with source “http://test2:8000/tools/js/spin.js”.

405 Request method 'GET' not supported.

和发生这一切的页面的网址是http://test2:8000/tools/tsub

更新

在 web.xml 文件中,我有以下内容

...
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
...
<filter-mapping>
        <filter-name>domainTrafficDispatcher</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

这是一个问题吗?

标签: embedded-jettysni

解决方案


@joakimerdfelt 所以经过大量的拉头发工作后,我已经解决了我的问题。

在解决这个问题的过程中,我添加了一个新的来处理对 /js/ 、 /images/Controller等的“默认”引用,并认为这至少可以解决问题。它没有。

在拉了很多头发之后,事实证明,两年前有人为更旧版本的软件添加了映射(显然没有)。我删除了这些映射并添加了安全配置,以便在获取该类型的文件时不应用任何安全性。安全适用于所有其他参考。我删除了Controller将完成的默认处理,并且......这一切都刚刚开始按应有的方式工作。

感谢所有的建议。


推荐阅读