2

我正在尝试使用 Swagger 启动我们的 API 服务器。我们根本不使用 web.xml,而是用 Java 配置所有内容。我正在尝试按照Swagger JAX-RS 教程中的说明进行操作,但仍然遇到问题。我正在使用 Git 的最新代码(本地安装的 1.2.1-SNAPSHOT)

final Server jetty = injector.getInstance(Server.class);

ServletContextHandler sch = injector.getInstance(ServletContextHandler.class);
sch.setInitParameter("swagger.api.basepath", "http://localhost:8090");
sch.setInitParameter("api.version", "0.1");

JuiceContainer unprotected = new JuiceContainer(injector, ApiListingResource.class);
sch.addFilter(new FilterHolder(unprotected), "/*", null);
sch.addServlet(DefaultServlet.class, "/");

ApiListingResource 正是教程中建议的方式:

@Path("/resources.json")
@Api("/resources")
@Produces(MediaType.APPLICATION_JSON)
public class ApiListingResource extends JavaApiListing { }

不幸的是,在启动服务器时出现此错误:

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.jaxrs.JavaApiListing.getAllApis(javax.servlet.ServletConfig,javax.ws.rs.core.Application,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo) at parameter at index 0
  SEVERE: Method, public javax.ws.rs.core.Response com.wordnik.swagger.jaxrs.JavaApiListing.getAllApis(javax.servlet.ServletConfig,javax.ws.rs.core.Application,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo), annotated with GET of resource, class com.wordnik.swagger.jaxrs.JavaApiListing, is not recognized as valid resource method.
4

1 回答 1

2

我自己在 Swagger 中解决了这个问题;现在有一个拉取请求打开。

于 2013-03-13T18:33:26.573 回答