【发布时间】:2017-06-12 22:41:26
【问题描述】:
这是我的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>
我正在使用 Spring Boot 的 1.5.3.RELEASE 版本。这是我的招摇配置文件:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket swagger() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
这是我的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/**");
}
当我从端点 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
}
但是当我尝试访问localhost:8080/swagger-ui.html 的 UI 时,我得到一个如下所示的空白页面:
我做错了什么?这是某种春季安全问题吗?
【问题讨论】:
-
你能把你的代码放在什么地方吗?
-
尝试在
SwaggerConfig类中将方法名称从swagger()更改为api()。 -
尝试使用url:localhost:8080/swagger-ui.html#,末尾有#符号
-
显示你的控制器?
标签: java spring spring-boot spring-security swagger