這裏是我的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#/,並在末尾加上**#**符號 –