加载swaggerui时java获取错误。spring中的html(5.0.0.RELEASE)mvc
无法解析引用,因为:无法解析指针:/definitions/文档中不存在错误
我遵循了这个链接http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api,但在为自定义响应消息添加globalResponseMessage()方法时出现了上述错误。我不明白原因是什么。 请帮忙。。。。短暂性脑缺血发作
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.consumes(getContentType())
.produces(getContentType())
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, newArrayList(
new ResponseMessageBuilder()
.code(500).message("500 message")
.responseModel(new ModelRef("Error")).build(),
new ResponseMessageBuilder()
.code(403)
.message("Forbidden!!!!!")
.build()));
}
# 1 楼答案
应该使用基本类,比如字符串。如果要使用自定义类(比如Error),应该在摘要定义中添加
additionalModels(typeResolver.resolve (CustomResponseClass.class))
来解析此模型。下面是一个运行良好的代码:其中
TypeResolve
来自com.fasterxml.classmate
包结果图像: documentation result
# 2 楼答案
你有两个选择:
1)将“错误”替换为“字符串”(小写)
2)将“Error”替换为响应正文中用于错误信息的类的名称(或为此定义一个
Error
类)。例如:在本例中,类
ErrorInfo
应该位于web应用程序的类路径中(可以位于多个web应用程序共享的库中)。例如: