我能够通过使用BeanConfig配置swagger而不是在web.xml中使用Servlet来解决此问题
BeanConfig类:
public class SwaggerBootstrap extends DefaultJaxrsConfig {
/**
*
*/
private static final long serialVersionUID = myAutoGeneratedID;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
//contextPath will be null for host2 and /xyz for host1.
String contextPath = config.getServletContext().getContextPath();
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.0");
beanConfig.setTitle("My API Documentation");
beanConfig.setSchemes(new String[] {
"http", "https"
});
beanConfig
.setResourcePackage("com.example.my.rest.api.package");
beanConfig.setBasePath(contextPath + "/rest");
beanConfig.setScan(true);
}
}
并在web.xml中:
SwaggerBootstrap
my.package.to.SwaggerBootstrap
scan.all.resources
true
2
我改变了我的pom.xml以开始使用最新稳定版本的swagger-jersey2-jaxrs:
io.swagger
swagger-jersey2-jaxrs
1.5.3