What I did is to use Grizzly
/Jersey
to host swagger-ui
, which is static content.
Here's part of 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'
Here's how to configure static content with Grizzly
:
httpServer = GrizzlyWebContainerFactory.create(uri);
httpServer.getServerConfiguration().addHttpHandler(new StaticHttpHandler("swagger-ui"), "/swagger");
swagger-ui
is the folder under the project root folder.
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:
I'm wondering what's the best way to make url without trailing slash(/) to be the same as those with trailing slash.
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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…