我想使用Swagger 2.0和Spring Boot RESTful web服務來生成文檔。我已經搜索了相當多的答案。基本上我有一個控制器的Spring Boot項目,我想記錄API的。我在我的POM文件中設置了以下依賴項。Swagger Spring Boot的REST API文檔
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.5.0</version>
</dependency>
這是我揚鞭配置類與@Configuration和@ EnableSwagger2:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*"))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("My application title")
.description("This is a test of documenting EST API's")
.version("V1.2")
.termsOfServiceUrl("http://terms-of-services.url")
.license("LICENSE")
.licenseUrl("http://url-to-license.com")
.build();
}
}
從我所聚集在閱讀了幾個其他的答案在這裏,在這一點上,我應該能夠看到一些網址,如http://myapp/v2/api-docs或http://localhost:8080/myapp/api-docs我做了一個假設,上面的URL的「myapp」部分引用了我的主要駐留的類的名稱(這是否正確)?我也嘗試過使用端口8080和端口80,而底線是我看不到其他網站無法訪問的東西。我已經看過提供的答案here和here但是我沒有取得任何成功。任何幫助將不勝感激,先謝謝你。
試試這個:HTTP://本地主機: 8080/myapp/swagger-ui.html –