0
我有一個spring引導1.5.1RELEASE應用程序,我試圖使用Swagger。我加了依賴性:Spring Boot和Swagger
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.5.0'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.5.0'compile('org.springframework.boot:spring-boot-devtools')
compile("org.springframework.boot:spring-boot-starter-web:1.5.1RELEASE)
然後A /配置類:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("My API Documentation ")
.description("Swagger API Documentation provided for your viewing pleasure")
.version("1.0")
.build();
}
}
我有一個GET端點
@Api(value = "/words", description = "Words API", produces = "application/json")
@RestController
@RequestMapping("/words")
public class WordsController {
@ApiOperation(value = "getAllWords", nickname = "getAllWords",
response = ResponseEntity.class, httpMethod = "GET")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = ResponseEntity.class),
@ApiResponse(code = 500, message = "Failure")
})
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public ResponseEntity getAllWords() {
...}
但是,當我在http://localhost:3000/swagger-ui.html
訪問我的API(我有我服務器配置爲在端口3000上運行我只能看到綠色的招牌吧
我建立這一關幾個教程,但我不明白爲什麼我的文檔揚鞭沒有被呈現
我認爲我通過將我的SwaggerConfig移動到我的主類中來修復它,所以出於某種原因,這個@Configuration沒有被拾取 – sonoerin