In the pursuit of troubleshooting the "406 Not Acceptable" error encountered when performing a JSON request in Spring, we delve into the cause and provide a solution.
According to the HTTP response status code definition, this error signifies that the requested resource cannot generate responses with acceptable content characteristics based on the accept headers in the request.
In your scenario, the request accepts application/json, but the controller lacks the capability to produce responses in that format. Typically, this occurs when the appropriate HTTPMessageConverter is not available to process the @ResponseBody-annotated return value.
HTTPMessageConverters are registered automatically when using
To resolve this issue, ensure that you have the correct Jackson library in your classpath:
Additionally, ensure that you have the
By implementing these changes, you should be able to successfully make JSON requests and receive responses without encountering the 406 error.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3