我們使用spring 4.x和swagger-jersey2-jaxrs_2.10。 Swagger沒有列出我的API,它總是隻返回版本信息。Jersey 2 + Swagger返回空列表API
的pom.xml
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
<version>1.3.13</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.23.2</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
</exclusions>
</dependency>
的web.xml
<filter>
<filter-name>SpringApplication</filter-name>
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>xxx.xxx.xxx.filter.JerseyApiSpringFilter</param-value>
</init-param>
<init-param>
<param-name>jersey.config.servlet.filter.forwardOn404</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
<param-value>/docs/.*</param-value>
</init-param>
</filter>
資源類
@Path("/listApi")
@Component
@Scope("request")
@Api(value = "/listApi", description = "List API")
@Produces({"application/json"})
public class ListApiResource {
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Retrieve all list of apps", response = listDto.class)
public Response getAllApps (@QueryParam("appId") int appId) {
// code
}
}
ResourceConfig類
public class JerseyApiSpringFilter extends ResourceConfig {
static {
// JaxrsApiReader.setFormatString("");
}
public JerseyApiSpringFilter() {
packages("com.xxx.xxxx.xxxxxx.resources");
register(RequestContextFilter.class);
register(ApiListingResource.class);
register(ApiListingResourceJSON.class);
register(JerseyApiDeclarationProvider.class);
register(JerseyResourceListingProvider.class);
register(MultiPartFeature.class);
register(JacksonFeature.class);
}
我的應用程序basebath/API的文檔返回
{
"apiVersion": "1.0.0",
"swaggerVersion": "1.2",
}
此代碼是沒有幫助我..請提供一個合適的解決方案,以解決我的問題.. – SST