I have a simple rest controller :
@RestController
@RequestMapping("/api/v1/")
public class OrderController {
@RequestMapping(value = "/orders2", method = RequestMethod.POST)
public OrderDto createOrder2(@RequestBody OrderDto order) throws Exception {
throw new Exception("Bouh!");
}
}
And I want to manage exceptions globally. From what I read it can be done with something like :
@ControllerAdvice
public class ErrorController {
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public ErrorDto handleConflict(HttpServletRequest request, Exception e) throws Exception {
ErrorDto o = new ErrorDto ();
o.setMessage(e.getMessage());
return o;
}
}
But when I make a post on my request, I get the following error :
26/10/2016 17:26:08.187 [http-nio-8080-exec-12] WARN o.s.web.servlet.PageNotFound -
No mapping found for HTTP request with URI [/duorest/api/v1/api/v1/orders2]
in DispatcherServlet with name 'rest'
I don't know why the uri change to /duorest/api/v1/api/v1/orders2
Some facts :
- I checked in debug, my code is executed
- If I move the method in the rest controller, I get no error and what I expect (my ErrorDto object)
- Spring framework version 4.3.3.RELEASE
- Spring-data-rest-webmvc version 2.5.4.RELEASE
Anybody already had this problem ? Or any hint ?