本文介绍了Swagger没有通过Spring Boot检测到Spring Data Rest API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个Spring Boot项目,其中包括Spring Data Rest和Swagger:

I setup a Spring Boot project including Spring Data Rest and Swagger:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.4.0</version>
</dependency>
<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.4.0</version>
</dependency>

这是我的Swagger配置:

This is my Swagger configuration:

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}

application.properties的摘录:

Excerpt from application.properties:

spring.data.rest.base-path=/api
server.context-path=/myapp

运行服务器时,所有其余端点均已正确映射并可以访问/myapp/api/...,包括我自己创建的自定义RestController.

When I run the server, all rest endpoints are correctly mapped and reachable to /myapp/api/..., including a custom RestController I created on my own.

但是:

    http://localhost:8080/myapp/api上的
  • 我可以看到Spring的列表Data Rest API(Json格式),但看不到我的自定义RestController端点.

  • at http://localhost:8080/myapp/api I can see the list of SpringData Rest APIs (in Json format) but cannot see my custom RestController endpoints.

上,我看到一个不错的gui,它仅列出了我的自定义RestController和错误端点,而不列出Spring Data Rest API.实际上, http://localhost:8080/myapp/v2/api-docs 确实可以不会引用任何Spring Data Rest端点,而只引用我自定义的RestController和错误端点.

at http://localhost:8080/myapp/swagger-ui.html I see a nice gui which only lists my custom RestController and the error endpoint, not the Spring Data Rest APIs. In fact, http://localhost:8080/myapp/v2/api-docs does not make any reference to Spring Data Rest endpoints, but only to my custom RestController and to the error endpoint.

如何修复Spring Data Rest&昂首阔步的配置?

How can I fix my Spring Data Rest & Swagger configuration?

推荐答案

Spring Data Rest支持仅在springfox 2.6.0版本中引入.如果您升级到以下版本,则按照说明最新版本的springfox(在撰写本文时为2.6.1),渲染端点应该没有问题.

Spring Data Rest support was only introduced in springfox version 2.6.0. If you follow the instructions after upgrading to the latest version of springfox (2.6.1 at the time of this writing) you shouldn't have a problem with rendering the endpoints.

这篇关于Swagger没有通过Spring Boot检测到Spring Data Rest API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:50