0
我已經通過Swagger文檔並根據文檔對其進行了配置。在Jersey + Spring + Tomcat環境中沒有生成swagger.json
當我要求http://localhost:8080/rest/api-docs頁,揚鞭正確地顯示所有信息,但它不產生swagger.json,所以http://localhost:8080/rest/swagger.json返回404
我的終點http://localhost:8080/rest/test也能正常工作。
這裏是我的web.xml
:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.test.JerseyConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Swagger Config -->
<servlet>
<servlet-name>Jersey2Config</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8080/rest/</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
JerseyConfig
類:
public class JerseyConfig extends ResourceConfig {
public JerseyConfig() {
register(Test.class);
//....
// Swagger
register(com.wordnik.swagger.jersey.listing.ApiListingResource.class);
register(com.wordnik.swagger.jersey.listing.ApiListingResourceJSON.class);
register(com.wordnik.swagger.jersey.listing.JerseyApiDeclarationProvider.class);
register(com.wordnik.swagger.jersey.listing.JerseyResourceListingProvider.class);
}
}
Test.class
是一個簡單的端點,與揚鞭@Api註解。
@Path("/test")
@Api(value = "/test", description = "tttttt")
public class TestResource {
@GET
@ApiOperation(value = "Checks server")
@ApiResponses(@ApiResponse(code = 200, message = "Server is available"))
public Response check() {
return Response.ok().build();
}
}
應用程序部署在Tomcat中。
據新澤西ResourceModel,由揚鞭創建的唯一終點是:
GET /api-docs
GET /api-docs/{route: .+}