AffirmPaymentController POST请求不支持问题求助
I'm stuck with an issue where my AffirmPaymentController's /authorise endpoint rejects POST requests, even though I've explicitly included both POST and GET in the @RequestMapping method list. GET requests work fine, but any POST (even without parameters) throws a method not supported error.
My Controller Method
@RequestMapping(value = "/authorise", method = {RequestMethod.POST,RequestMethod.GET}) public String authorise(@RequestParam(name = "checkout_token", required = false) final String checkoutToken, final Model model, final RedirectAttributes redirectModel) { boolean success = false; try { success = affirmPaymentFacade.authorisePayment(checkoutToken); } catch (RuntimeException re) { LOG.warn("error during payment authorisation ", re); } if(success){ final OrderData orderData; try { orderData = getCheckoutFacade().placeOrder(); } catch (final Exception e) { LOG.error("Failed to place Order", e); //TODO-BE auth reversal //GlobalMessages.addErrorMessage(model, "checkout.affirm.order.failed"); return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR; } return redirectToOrderConfirmationPage(orderData); }else { //GlobalMessages.addErrorMessage(redirectModel,"checkout.affirm.authorisation.failed"); return REDIRECT_PREFIX + CHECKOUT_AFFIRM_ERROR; } }
The Error I See
When sending a POST request with checkout_token=XXXX in the request body, this warning shows up in the logs:
WARN [hybrisHTTP24] [DefaultHandlerExceptionResolver] Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
Quick Update: I even tried removing all parameters from the method signature entirely, and the problem still happens.
Here’s How to Fix This
Let’s go through the most common culprits and fixes for this issue, especially in a Hybris context:
Check for conflicting endpoint mappings
Double-check if another controller (either in your custom code or Hybris OOTB) has a mapping for/authorisethat only allows GET requests. Sometimes a@PostMappingor a narrower@RequestMappingelsewhere can override your mapping. Search your codebase for other instances of/authorisepaths to rule this out.Validate your request content type
If your POST is sending JSON but you’re using@RequestParam(which expects query params or form-encoded data), Spring might not parse the request correctly, leading to a misleading method not supported error. Either switch to sendingapplication/x-www-form-urlencodeddata, or use@RequestBodywith a simple DTO to capture the checkout token from JSON.Spring Security might be blocking POSTs
Hybris uses Spring Security heavily, so check if your security config is restricting POST requests to this endpoint. For example, if CSRF protection is enabled and you’re not sending a CSRF token with your POST, that could trigger this error. Look into yourspring-security-config.xmlor any custom security filters that might be interfering.Confirm class-level request mappings
Make sure yourAffirmPaymentControllerdoesn’t have a class-level@RequestMappingwith a prefix you’re missing in your request URL. For example, if the class has@RequestMapping("/affirm-payment"), the full endpoint is/affirm-payment/authorise—sending requests to just/authorisewould hit the wrong mapping.Clear Hybris caches and rebuild
Hybris can sometimes hold onto old mapping configurations after code changes. Runant clean alland restart your server to ensure the latest controller mappings are loaded properly.Enable debug logging for Spring MVC
Turn on debug logs fororg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping. This will show you exactly which mappings Spring has registered, so you can confirm if your/authoriseendpoint is actually set up to accept POST requests.
内容的提问来源于stack exchange,提问作者Erturgul

