这里是我的pom.xml
:春天引导扬鞭API不工作
<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启动的版本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
我得到一个空白页面,看起来像这样:
我在做什么错?这是春季安全问题吗?
你可以把你的代码放在什么地方吗? – chenrui
尝试将方法名称从'swagger()'更改为'SwaggerConfig'类中的'api()'。 –
尝试使用url:http:// localhost:8080/swagger-ui.html#/,并在末尾加上**#**符号 –