2017-09-11 11 views
2

다음의 지침 :Springfox Swagger-UI를 추가했는데 작동하지 않습니다. 무엇이 누락 되었습니까? 여기

http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

나는 내 프로젝트에 이러한 종속성을 추가 :

compile "io.springfox:springfox-swagger2:2.7.0" 
compile "io.springfox:springfox-swagger-ui:2.7.0" 

과 같은 SpringFox 자신감을 구성 :

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import springfox.documentation.builders.PathSelectors; 
import springfox.documentation.builders.RequestHandlerSelectors; 
import springfox.documentation.spi.DocumentationType; 
import springfox.documentation.spring.web.plugins.Docket; 
import springfox.documentation.swagger2.annotations.EnableSwagger2; 

@Configuration 
@EnableSwagger2 
public class SwaggerConfig { 
    @Bean 
    public Docket api() { 
     return new Docket(DocumentationType.SWAGGER_2) 
       .select() 
       .apis(RequestHandlerSelectors.any()) 
       .paths(PathSelectors.any()) 
       .build(); 
    } 
} 

하지만 자신감 UI가 보인다 사용할 수 없게됩니다. 나는 시도 :

내가 가진 전부입니다

Whitelabel Error Page 

This application has no explicit mapping for /error, so you are seeing this as a fallback. 

Mon Sep 11 09:43:46 BST 2017 
There was an unexpected error (type=Method Not Allowed, status=405). 
Request method 'GET' not supported 

및 로그에 나는 참조 :

2017-09-11 09:54:31.020 WARN 15688 --- [nio-8080-exec-6] o.s.web.servlet.PageNotFound    : Request method 'GET' not supported 
2017-09-11 09:54:31.020 WARN 15688 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported 

http://localhost:8080/swagger-resources 반환 : 나는 무엇을

[{"name": "default", 
    "location": "/v2/api-docs", 
    "swaggerVersion": "2.0"}] 

를 놓친 거지?

+0

액세스를 방해 할 수있는 스프링 보안 기능이 있습니까? – StanislavL

+0

@StanislavL : 아니요, 아직 보안 기능을 활성화하지 않았습니다. – Pablo

+0

@StanislavL : 내가 얻은 로그 오류를 추가했고 PageNotFound입니다. – Pablo

답변

3

이 형식의 경로 변수가있는 요청 매핑이있는 끝점이 있기 때문에이 문제가 발생했습니다./{var}. 이것이 GET 및 POST 끝점 (GET/{var} 및 POST/{var} swagger-ui)에 모두 문제가 있음을 알 수 있습니다. 경로를 좀 더 구체적으로 만들었을 때, 나는 일할 swagger-ui를 얻었다.

견적 https://github.com/springfox/springfox/issues/1672 스프링이 URL을 가로 챌 수없는 하나의 변수 자신감 간단한 경로를 발견

에서.

의견에서 다양한 아이디어를 조사하여 발견되었습니다.