question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

http 406 not acceptable issue - spring 4 , springfox-swagger2

See original GitHub issue

Hi,

Hi I am getting “The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request “accept” headers” error i.e Http 406 not acceptable. I am using spring 4

I am using the below dependencies

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.4.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.4.1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.4.1.1</version>
</dependency>
<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-core-asl</artifactId>
    <version>1.9.13</version>
</dependency>
<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.13</version>
</dependency>

My swagger config file is as below

@EnableSwagger2
@Configuration
public class SwaggerConfig {
	
	 @Bean
	    public Docket api() { 
	        return new Docket(DocumentationType.SWAGGER_2)  
	          .select()                                  
	          .apis(RequestHandlerSelectors.any())              
	          .paths(PathSelectors.any())                          
	          .build();                                           
	    }
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
        http://www.springframework.org/schema/context   
        http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
	<context:component-scan base-package="com.fmrco.research.search" />
	<bean id="swaggerConfig" class="com.fmrco.research.search.swagger.SwaggerConfig">
		<!-- <property name="basePackage" value="com.fmrco.research.search" /> 
			<property name="serviceAPITitle" value="API - Swagger service" /> <property 
			name="serviceDescription" value="This is a Swagger-enabled API representation 
			for Swagger POC" /> <property name="serviceVersion" value="1.0" /> <property 
			name="consumptionFormat" value="application/json" /> -->
	</bean>
	<mvc:annotation-driven />
	<context:annotation-config />
	<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
	<mvc:resources mapping="/webjars/**"
		location="classpath:/META-INF/resources/webjars/" />
</beans>

My controller definition is as below

 @RequestMapping(value = "/{dataSource}/search", method = {
            RequestMethod.GET, RequestMethod.POST })
    public ResponseEntity<?> search(
            @PathVariable("dataSource") String dataSource,
            @RequestParam @RequestBody MultiValueMap<String, String> allRequestParams,
            @RequestHeader HttpHeaders headers) { ...
            }

Also CORS filter is setup. Anything is missing ? How do i resolve this. I have attached all the files. Please let me know how do i resolve this

swaggerfiles.zip

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dilipkrishcommented, Nov 22, 2016

I mean use a tool like postman that allows you to specify an Accept header and set the value to application/json

1reaction
dilipkrishcommented, Nov 21, 2016

Seems like if you pass in application/json everything should just work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springfox-Swagger2 406 not acceptable error -Spring 4
It is working fine. I dont have to add any request parameters. Above link is giving me the response. When I hit http://localhost:8080/endpoint/ ......
Read more >
406 Not Acceptable - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 406 Not Acceptable client error response code indicates that the server cannot produce a response ...
Read more >
406 Not Acceptable: What It Is and How to Fix It - Airbrake Blog
The 406 Not Acceptable is an HTTP response status code indicating that the client has requested a response using Accept- headers that the ......
Read more >
Http Status 406 In Rest Api Spring Boot When Getbyemail
SpringBoot get request return error code 406 Not Acceptable Programmer Annotation ... http 406 not acceptable issue spring 4 springfoxswagger2 #1573.
Read more >
How to Fix a 406 Error and Find the Source of the ... - Kinsta
The 406 error not acceptable message has several options for ... The “406 error” or “406 Not Acceptable” error is one such HTTP...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found