こんにちは私は「このリクエストで特定されたリソースはリクエストに応じて受け入れられない特性を持つレスポンスを生成することしかできません」という「ヘッダ」エラーを受け取ります。Springfox-Swagger2 406受け入れられないエラー-Spring 4
私が闊歩については、以下の依存関係を使用しています
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.3-M1</version>
</dependency>
マイ闊歩の設定ファイルは、フィルタは、プロジェクトの設定でCORS
@EnableSwagger2
@Component
public class SwaggerConfig {
@Bean
public Docket swaggerSpringMvcPlugin() {
ArrayList<ResponseMessage> standardExpectedHttpResponses =
createStandardExpectedHttpResponses();
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET,
standardExpectedHttpResponses)
.globalResponseMessage(RequestMethod.POST,
standardExpectedHttpResponses)
.globalResponseMessage(RequestMethod.PUT,
standardExpectedHttpResponses)
.globalResponseMessage(RequestMethod.DELETE,
standardExpectedHttpResponses)
/*.globalOperationParameters((List<Parameter>) new ParameterBuilder()
.name("xyz=id")
.description("Description of someGlobalParameter")
.modelRef(new ModelRef("string"))
.parameterType("query")
.required(true)
.build())*/
.produces(createStandardProducesConsumes())
.consumes(createStandardProducesConsumes()).pathMapping("")
.select()
.apis(RequestHandlerSelectors
.basePackage("com.x.y.z"))
.paths(PathSelectors.ant("/*"))
.build().apiInfo(metadata());
}
private ApiInfo metadata() {
return new ApiInfoBuilder()
.title("API - xyz")
.description(
"This is a Swagger-enabled API representation for the xyz.")
.version("1.0").build();
}
private ArrayList<ResponseMessage> createStandardExpectedHttpResponses() {
ArrayList<ResponseMessage> messages = new ArrayList<ResponseMessage>();
messages.add(new ResponseMessage(200, "Ok", null));
messages.add(new ResponseMessage(400, "Bad Request", null));
messages.add(new ResponseMessage(401, "Unauthorized", null));
messages.add(new ResponseMessage(403, "Forbidden", null));
messages.add(new ResponseMessage(404, "Not Found", null));
messages.add(new ResponseMessage(500, "Internal Server Error", null));
return messages;
}
private HashSet<String> createStandardProducesConsumes() {
HashSet<String> producesConsumes = new HashSet<String>();
producesConsumes.add("application/json");
return producesConsumes;
}
}
以下の通りです。何かが欠落していますか?どのように私はこれを解決するのですか?
私がサービスを打つと、私に応答が与えられます。それは正常に動作しています。私は任意のリクエストパラメータを追加する必要はありません。上のリンクは私に応答を与えています。
私がhttp://localhost:8080/endpoint/v2/api-docsにヒットしたとき、私はhttpの406エラーがあります。私は私のサービスに注釈を追加する必要がありますか?
あなたのCORSフィルター投稿することができますか? CORSフィルタにすべての応答ヘッダーを設定しなかったので、同様の問題が発生しました。そしてあなたの卑劣な依存性をアップグレードしようとします。私はバージョン2.5.0を使用します。 (そして私はちょうどバージョン2.6.1がリリースされているのを見て) – YLombardi
確かに..応答ありがとう。以下は私のCORSフィルタです。 –
私は以下のCORSフィルターを追加しました –