在spring(5.0.0.RELEASE)mvc中加载swagger-ui.html时出错 [英] Getting error while loading swagger-ui.html in spring(5.0.0.RELEASE) mvc

查看:131
本文介绍了在spring(5.0.0.RELEASE)mvc中加载swagger-ui.html时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于以下原因而无法解析引用:无法解析指针:/definitions/错误在文档中不存在

我点击了此链接

解决方案

您有两种选择:

1)将错误"替换为字符串"(小写).

 新的ResponseMessageBuilder().code(500).message("500条消息").responseModel(new ModelRef("string")).build(), 

2)将错误"替换为您在响应正文中用于错误信息的类的名称(或为此定义一个 Error 类).示例:

 新的ResponseMessageBuilder().code(500).message("500条消息").responseModel(new ModelRef("ErrorInfo")).build(), 

在此示例中,类 ErrorInfo 应该位于Web应用程序的类路径中(可以位于由多个Web应用程序共享的lib中).示例:

  @XmlRootElement公共类ErrorInfo {私人字串网址;@ApiModelProperty(notes ="HTTP状态代码")private int statusCode;@ApiModelProperty(notes ="HTTP原因短语")私有String reasonPhrase;@ApiModelProperty(notes =对用户的管理")私有字符串消息;@ApiModelProperty(备注=在IT服务台上创建的票证(如果适用)",必填=否)私有字符串helpDeskTicket;@ApiModelProperty(notes =调试信息(例如,堆栈跟踪),如果运行时环境为生产"则不可见",必填= false)私有字符串debugInfo;公共ErrorInfo(){//杰克逊反序列化所需.}//...其他构造函数,get/set方法...} 

Could not resolve reference because of: Could not resolve pointer: /definitions/Error does not exist in document

I followed this link http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api , but getting above error while I add globalResponseMessage() methhod for custom response message.I can't understand what's the reason. Please help....TIA

 @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()));
}

解决方案

You have two alternatives:

1) Replace "Error" with "string" (lower case).

new ResponseMessageBuilder()
                        .code(500).message("500 message")
                        .responseModel(new ModelRef("string")).build(),

2) Replace "Error" with the name of the class you use for error information in the response body (or define an Error class for that). Example:

new ResponseMessageBuilder()
                        .code(500).message("500 message")
                        .responseModel(new ModelRef("ErrorInfo")).build(),

In this example, class ErrorInfo should be in the classpath of your web application (could be in a lib shared by several web apps). Example:

@XmlRootElement
public class ErrorInfo {

    private String url;

    @ApiModelProperty(notes = "HTTP Status Code")
    private int statusCode;

    @ApiModelProperty(notes = "HTTP Reason Phrase")
    private String reasonPhrase;

    @ApiModelProperty(notes = "Mensage to the user")
    private String message;

    @ApiModelProperty(notes = "Ticket created on IT help desk if applicable", required = false)
    private String helpDeskTicket;

    @ApiModelProperty(notes = "Debug information (e.g., stack trace), not visible if runtime environment is 'production'", required = false)
    private String debugInfo;

    public ErrorInfo() {
        // required by Jackson deserialization.
    }

    // ... other constructors, get/set methods...

}

这篇关于在spring(5.0.0.RELEASE)mvc中加载swagger-ui.html时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆