Jersey 2:正确渲染Swagger静态内容而不使用斜线(/) [英] Jersey 2: render Swagger static content correctly without trailing slash(/)
问题描述
我所做的是使用> 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
项目根文件夹。
当我访问 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没有结尾斜杠(/)是一样的那些跟踪斜线。
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
现在找不到解决方案。我正在考虑使用另一个web服务器。
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静态内容而不使用斜线(/)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!