I am throwing exception in a scenario. Which is handled by @ExceptionHandler
. But when throwing exception it says Request method 'POST' not supported
Controller code
@RequestMapping(value = "abcd", method = {RequestMethod.POST,RequestMethod.GET })
public String testAbc(Model model, HttpServletRequest request) throws Exception {
//some piece of code
if(someCondition)
throw new Exception("No data found with id ");
}
Code in ExceptionController class
@ExceptionHandler(Exception.class)
public ModelAndView handleException(Exception ex, HttpServletRequest request, HttpServletResponse response) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("errorMessage", ex.getMessage());
modelAndView.addObject("errorDetails", ExceptionUtils.getStackTrace(ex));
modelAndView.setViewName("forward:errorPage");
return modelAndView;
}
Have no idea what I am doing wrong.