2017-09-11 6 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

私はこの形式のパス変数を持つ要求マッピングを持つエンドポイントを持っていたため、この問題が発生しました。これはGETとPOSTの両方のエンドポイント、つまりGET/{var}とPOST/{var}がswagger-uiをブロックするための問題であることが判明しました。いったん私はパスをより具体的にした、私は仕事をswagger-ui得た。春はただ一つの変数闊歩して簡単なパスを見つけるとURLを傍受することはできませんhttps://github.com/springfox/springfox/issues/1672

から

引用。

コメントでさまざまなアイデアを調査しています。

関連する問題