2
我試圖用Swagger啓動我們的API服務器。我們根本不使用web.xml,而是用Java配置所有的東西。我試圖按照the Swagger JAX-RS tutorial的說明操作,但仍然有問題。我用從SVN最新的代碼(本地安裝1.2.1-SNAPSHOT)在Java中配置的Swagger缺少依賴關係
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.
你在使用Grizzly2嗎?這似乎是澤西和灰熊2已知的問題,請參閱http://java.net/jira/browse/JERSEY-1047。 Swagger提出了一個要求解決(或解決)問題的拉取請求,但它所做的更改被稍後的拉取請求(https://github.com/wordnik/swagger-core/pull/64)取消。我通過切換到使用Jetty而不是Grizzly2來修復問題 – InPursuit 2013-02-19 01:26:07
不,我正在使用Jetty。 – 2013-02-19 04:39:39
當使用servlet而不是過濾器時它工作正常 - 請參閱https://www.bountysource.com/issues/38004856-jersey1-19-swagger-have-a-exception-for-com-sun-jersey-spi-注 - 錯誤 - errormessagesexception空 – koppor 2017-10-03 17:40:39