Spring Boot Swagger API 不起作用

Ric*_*ard 3 java spring spring-security swagger spring-boot

这是我的pom.xml

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.7.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我正在使用1.5.3.RELEASESpring Boot 的版本。这是我的招摇配置文件:

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket swagger() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的WebSecurityConfig.java

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**");
}
Run Code Online (Sandbox Code Playgroud)

当我从端点http://localhost:8080/v2/api-docs获取时,我会返回我的 JSON:

{
  "swagger": "2.0",
  "info": {
    "description": "Api Documentation",
    "version": "1.0",
    "title": "Api Documentation",
    "termsOfService": "urn:tos",
    "contact": {},
    "license": {
      "name": "Apache 2.0",
      "url": "http://www.apache.org/licenses/LICENSE-2.0"
    }
  },
  "host": "localhost:8080",
  "basePath": "/",
  //ETC
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试访问 UI 时,localhost:8080/swagger-ui.html我得到一个如下所示的空白页面: 在此处输入图片说明

如果我点击页面,我会得到提升 在此处输入图片说明

我究竟做错了什么?这是某种弹簧安全问题吗?

jih*_*hor 5

您可以在应用程序配置中使用springfox.documentation.swagger.v2.path属性向 Swagger 建议 API 描述路径,例如 springfox.documentation.swagger.v2.path: /rest/docsapplication.yml.

在 github 上发布了一个例子。