0
votes

My data is successfully inserted into the database but I still keep getting this error. It's performing okay but I'm irritated cause I keep getting this error.
This is my code:

$.ajax
({
type: 'post',
url: '/SendMessage',
data: 
{
    message_id: 0,
    message_sender: user_id,
    message_to: item,
    message_info: message,
    message_time: dateFormat,
    message_seen: "NO"

},
success: function (response) 
{
    alert("success");
},
});

This is my controller: private static final String PATH = "/error";

@RequestMapping(value="/SendMessage" , method=RequestMethod.POST)
public void sendMessage(Message message) {
    messageService.saveOrUpdate(message);
}

@RequestMapping(value= PATH) 
public ModelAndView error404() {
    ModelAndView model = new ModelAndView("error/error404");
    return model;
}

@Override
public String getErrorPath() {
    return PATH;
}

application.properties

spring.mvc.view.prefix= /WEB-INF/jsp/
spring.mvc.view.suffix= .jsp

server.error.whitelabel.enabled= false 
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration

Error:

Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/error': {public org.springframework.web.servlet.ModelAndView com.rtc_insurance.controller.SubmitController.error404(), public org.springframework.web.servlet.ModelAndView com.rtc_insurance.controller.WebsiteController.error404()} at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:371) ~[spring-webmvc-5.0.9.RELEASE.jar:5.0.9.RELEASE]

Hoping you could help me. Thank you so much!!!

2
What is the error? - Jonathan JOhx
already added it :) - trumanblack1025
can you update this class code com.rtc_insurance.controller.WebsiteController? - Deadpool
what will I do? - trumanblack1025
Could you please share the code on WebsiteController? - Jonathan JOhx

2 Answers

0
votes

From the error it looks like you have declared multiple methods with the same url 'error' or same method signature.

So spring is not able to decide which url to map because it is getting multiple methods on same url.

0
votes

Assuming that the question is actually about the title of the question (Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/error' for POST)

I can say that:

  • Your controller and Ajax request are ok and are really irrelevant here
  • There is a mapping on /error that appears in one of your controllers

Spring has its own error handling (that can be overridden but probably not like you've tried to do) and it also maps to /error, so there is a clash of mappings here.

You can read more about spring boot error handling here (especially this part can be relevant)

Update: After you've updated the question, please take a look at com.rtc_insurance.controller.WebsiteController.error404 It must be your controller that is not compliant with spring boot error handling mechanisms mentioned in a links above in my answer