我正在尝试在我的球衣jax-rs应用程序中使用swagger。我按照以下步骤指定了对swagger的依赖关系,将Swagger-Core连接到Application中,并从a link配置和初始化Swagger。但是,当我看到tomcat日志时,收到错误消息:“严重:方法public javax.ws.rs.core.Response com.wordnik.swagger.jersey.listing.ApiListingResource.apiDeclaration的依赖项丢失”。在这种情况下,谁能告诉我该怎么办。
web.xml文件的内容
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/crunchify/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.wordnik.swagger.jaxrs.json,
com.crunchify.restjersey;
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
com.wordnik.swagger.jersey.listing.ApiListingResourceJSON,
com.wordnik.swagger.jersey.listing.JerseyApiDeclarationProvider,
com.wordnik.swagger.jersey.listing.JerseyResourceListingProvider
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<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/crunchify</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
添加了我的pom.xml的内容。
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
<version>1.3.12</version>
<scope>compile</scope>
</dependency>
带有注释的Java类。
package com.crunchify.restjersey;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import com.wordnik.swagger.annotations.*;
import com.wordnik.swagger.jersey.listing.ApiListingResource;
@Path("/ctofservice")
@Api(value = "/ctofservice", description = "Get details")
public class CtoFService {
@ApiOperation(value = "get by id",
notes = "Specify a valid id",
response = String.class)
@ApiResponses(value = {
@ApiResponse(code = 400, message =
"Invalid id supplied"),
@ApiResponse(code = 404, message = " not found")
})
@Path("{c}")
@GET
@Produces("application/xml")
public String convertCtoFfromInput(@ApiParam( value = "The id", required = true )
@PathParam("c") Double c) {
Double fahrenheit;
Double celsius = c;
fahrenheit = ((celsius * 9) / 5) + 32;
String result = "@Produces(\"application/xml\") Output: \n\nC to F Converter Output: \n\n" + fahrenheit;
return "<ctofservice>" + "<celsius>" + celsius + "</celsius>" + "<ctofoutput>" + result + "</ctofoutput>" + "</ctofservice>";
}
}
tomcat控制台上的错误...
INFO: Initiating Jersey application, version 'Jersey: 1.19.4 05/24/2017 03:46 PM'
Jul 16, 2019 12:05:13 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.wordnik.swagger.jersey.listing.ApiListingResource.apiDeclaration(java.lang.String,javax.ws.rs.core.Application,org.glassfish.jersey.servlet.WebConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo) at parameter at index 2
SEVERE: Method, public javax.ws.rs.core.Response com.wordnik.swagger.jersey.listing.ApiListingResource.apiDeclaration(java.lang.String,javax.ws.rs.core.Application,org.glassfish.jersey.servlet.WebConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo), annotated with GET of resource, class com.wordnik.swagger.jersey.listing.ApiListingResource, is not recognized as valid resource method.
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.wordnik.swagger.jersey.listing.ApiListingResource.resourceListing(javax.ws.rs.core.Application,org.glassfish.jersey.servlet.WebConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo) at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response com.wordnik.swagger.jersey.listing.ApiListingResource.resourceListing(javax.ws.rs.core.Application,org.glassfish.jersey.servlet.WebConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo), annotated with GET of resource, class com.wordnik.swagger.jersey.listing.ApiListingResource, is not recognized as valid resource method.