Jersey 2: render Swagger static content correctly without trailing slash(/)(Jersey 2:正确渲染 Swagger 静态内容,不带斜杠(/))
问题描述
我所做的是使用 Grizzly
/Jersey
来托管 swagger-ui
,这是静态内容.
What I did is to use Grizzly
/Jersey
to host swagger-ui
, which is static content.
这是 build.gradle
的一部分:
compile 'org.glassfish.jersey.core:jersey-server:2.22.1'
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.22.1'
compile 'org.glassfish.jersey.containers:jersey-container-grizzly2-servlet:2.22.1'
以下是使用 Grizzly
配置静态内容的方法:
Here's how to configure static content with Grizzly
:
httpServer = GrizzlyWebContainerFactory.create(uri);
httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler("swagger-ui"), "/swagger");
swagger-ui
是项目根文件夹下的文件夹.
swagger-ui
is the folder under the project root folder.
当我访问 http://localhost/swagger/
时一切正常,但当我尝试 http://localhost/swagger
时,它只提供了一个没有渲染的简单页面,似乎所有 css/js 文件都丢失了:
Everything is fine when I access http://localhost/swagger/
but when I try http://localhost/swagger
, it only gives a simple page without rendering, which seems all css/js files are missing:
我想知道使不带斜杠(/)的 url 与带有斜杠的 URL 相同的最佳方法是什么.
I'm wondering what's the best way to make url without trailing slash(/) to be the same as those with trailing slash.
更新:我已经向 swagger-ui 提出了一张票:https://github.com/swagger-api/swagger-ui/issues/1966 但它说这是 Grizzly
的配置问题,所以 Grizzly
的另一张票:https://java.net/jira/browse/GRIZZLY-1823
Update:
I've raised a ticket to swagger-ui: https://github.com/swagger-api/swagger-ui/issues/1966 but it said it's a configuration problem with Grizzly
so another ticket for Grizzly
: https://java.net/jira/browse/GRIZZLY-1823
现在没有找到解决方案.我正在考虑使用另一个网络服务器.
No solution found now. I'm thinking to use another web server.
推荐答案
我可以确认(正如 alexey 评论的那样)这个问题已经在最近版本的 Grizzly 中得到修复.
I can confirm that (as commented by alexey) this has since been fixed in a recent version of Grizzly.
您可以将其添加到您的 pom.xml
或更新版本号
You can either add this to your pom.xml
or update the version number
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>2.3.28</version>
</dependency>
Grizzly 会自动将 301 重定向从不带斜杠的网址返回到带有斜杠的网址.
And Grizzly will automatically return a 301 redirect from the url without the trailing slash, to one with the trailing slash.
这篇关于Jersey 2:正确渲染 Swagger 静态内容,不带斜杠(/)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Jersey 2:正确渲染 Swagger 静态内容,不带斜杠(/)
基础教程推荐
- 在for循环中使用setTimeout 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 动态更新多个选择框 2022-01-01