'Spring Cloud Gateway - getting 405 Method not allowed

I have a problem where I am using Spring Cloud Gateway to reach my microservices. One of them is the user-service which has, among other things, an authentication endpoint. It is a POST endpoint, where the user simply sends his/her email and password.

For service discovery, I am using Eureka.

The problem I'm facing is that when I hit that endpoint through the gateway, for example the first request returns a 405 Method not Allowed, and further requests work just fine. What's interesting is that the calls do reach the user-service (I can see in the logs how Hibernate queries my DB), but the gateway returns a 405 nonetheless. In the gateway I do have in the app.yml file for the predicates Method=GET,POST,PUT,DELETE, so this shouldn't be an issue, I think.

Everything is also put in separate docker containers.

I am using java 16 with the latest versions for each dependency.

If you need me to provide any additional information, please ask me to do so.

Thanks a lot!



Solution 1:[1]

In my case timeDuration was the clue, it was too short.

Solution 2:[2]

General Answer:

there are couple of reasons for this error:

  1. check if your service is working fine using access logs.
  2. when using spring cloud circuit breaker, if GET request is working fine and only POST request is returning 405, then a quick fix would be to increase timeoutDuration for timeLimiterConfig because POST request might be taking more time than what you had configured, or simply enable request logging in DEBUG and examine the issue
  3. if you have cors enabled in services then add configuration in api-gateway's application.yml file to allow Origins, Methods, Headers.

Case specific answer:

share you implementation code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wojciech Gaudnik
Solution 2 Amit Verma