UPDATED with SOLUTION below!!!
//
感谢Ron的建议,我略微修改了我的设置,使用BeanConfig而不是SwaggerConfig,并使其正常工作 . 为了做到这一点,我不得不修改servlet,并且(这是我认为缺少的部分)将BeanConfig条目添加到spring应用程序上下文文件中,以便spring获取资源 . 我在下面的更新中包含了我的代码中的注释,显示了旧的和新的/更新的代码 . 它继续使用SwaggerConfig(也许我刚刚在Spring应用程序上下文文件中遗漏了一些东西?)但是BeanConfig正常工作,所以我将保留原样 .
//
我试图让Swagger运行我的本地基于REST的Java应用程序并取得了相当大的进步 . 但是,当我试图让Swagger UI工作时,我似乎错过了一些简单的东西 .
每当我真正点击这个地址时:http://localhost:9082/mbl/index.html我'm getting the little green swagger header at the top but a blank white body with no content underneath. Shouldn' t我在页面正文中看到的不仅仅是这个?
我的堆栈是这样的:Java 6 / Wink / Spring 3.1 / Jackson 2.5 / JAX-RS(JSR-311),我正在使用以下Swagger jar :swagger-annotations-1.3.10.jar / swagger-core_2.10- 1.3.10.jar / swagger-jaxrs_2.10-1.3.10.jar .
{"apiVersion":"1.0","swaggerVersion":"1.2","info":{"title":"Java API","description":"The following documentation contains the REST Service API useful for interacting with web services.","termsOfServiceUrl":"terms of service","contact":"email@test.com","license":"license type","licenseUrl":"license url"}}
我可以看到这是从我的SwaggerServlet.java生成的,如下所示:
package com.somewhere.mblsvc.web;
import...
public class SwaggerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/* additional working code */
BeanConfig beanConfig;
public void setBeanConfig(BeanConfig beanConfig) {
this.beanConfig = beanConfig;
}
/* end additional working code */
@Override
public void init(ServletConfig servletConfig) {
try {
/* code from original post*/
// SwaggerConfig swaggerConfig = new SwaggerConfig();
// ConfigFactory.setConfig(swaggerConfig);
// swaggerConfig.setBasePath("/mbl/services");
// swaggerConfig.setApiVersion("1.0");
// swaggerConfig.setApiInfo(new ApiInfo("Java API", "The following //documentation contains the REST Service API useful for interacting with web //services.", "terms of service", "email@test.com", "license type", "license //url"));
// ScannerFactory.setScanner(new DefaultJaxrsScanner());
// ClassReaders.setReader(new DefaultJaxrsApiReader());
/* end code from original post*/
/* updated working code */
beanConfig.setBasePath("/mbl/x-services");
beanConfig.setVersion("1.0");
beanConfig.setResourcePackage("com.somewhere.mblsvc.resources");
beanConfig.setScan(true);
/* end updated working code */
} catch (Exception e) {
e.printStackTrace();
}
}
}
另外,我在我的spring应用程序上下文xml文件中有以下内容:
我的web.xml看起来像这样:
Wink Servlet
org.apache.wink.server.internal.servlet.RestServlet
Wink Servlet
/services/*
Swagger Servlet
com.somewhere.mblsvc.web.SwaggerServlet
-1
Swagger Servlet
/api-docs
这是我的Resource类的片段:
@Path("test")
@Api(value ="test", description="Test Services")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public class TestResource {
.
.
.
@GET
@Path("testInfo")
@ApiParam(defaultValue="you would put test case input here for a post")
@ApiOperation(value="Composite service returning extensive test information", response=com.somewhere.mblsvc.messages.test.testinfo.pojo.UserResponseMessage.class)
@ApiResponses(value={
@ApiResponse(code=200, message="OK"),
@ApiResponse(code=500, message="Internal Error")
})
@JsonSerialize(include=JsonSerialize.Inclusion.ALWAYS)
public Response getTestInfo(@Context HttpHeaders headers,
@CookieParam(value = "testBrand") String testBrand) {
.
.
.
最后,我的index.html唯一重要的部分(我可以告诉)看起来像这样:
$(function () {
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = url[1];
} else {
url = "http://" + window.location.hostname + (window.location.port ? ':'+ window.location.port: '') + "/mbl/services/api-docs";
}
.
.
.
我很乐意根据需要提供更多信息 . 有谁知道我可能会缺少什么?
非常感谢!