Spring -mvc: how to display URI patterns in the form "a / b / {c}"?

I can get a URI template in the form "/ a / b" or "/ a / {b}" to work. But when I try "/ a / b / {c}", I get an HTTP 404 and a log message in the form "There is no mapping found for the HTTP request with the URI [/ myapp / a / b / c ... ..." But I see this message in the log, and it makes me think that the comparisons are correct ...?

INFO: Mapped URL path [/a] onto handler 'AController' Nov 16, 2010 12:18:39 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/a/*] onto handler 'AController' Nov 16, 2010 12:18:39 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 

I noticed all the examples from spring -mvc docs showing URI patterns in the form "/ a / {b}" or / a / {b} / c / {d} ". So" / a / b / {c} " not possible? Is there anything I need to configure in web.xml for this to happen? Or maybe (or mis) for this template not to show up? Currently my dispatcher servlet is mapped to:

 <url-pattern>/</url-pattern> 

The controller is as follows:

 @Controller public class AController { @RequestMapping(value = "/a/b/{c}", method = RequestMethod.GET) public ModelAndView show() { ModelAndView modelAndView = new ModelAndView("A"); return modelAndView; } } 

Accessing http: // localhost: 8080 / myapp / a / b / c returns 404, and I see this in the log:

 Nov 16, 2010 12:19:06 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI [/myapp/a/b/c] in DispatcherServlet with name 'dispatcher' 

Any ideas on how I am drawing my URI pattern correctly?

+2
source share
3 answers

It seems that this only happens when ControllerClassNameHandlerMapping used as a handler mapping.

Annotated controllers are usually used with DefaultAnnotationHandlerMapping , in which case everything works fine.

EDIT: Actually, it looks like the legitimate behavior of ControllerClassNameHandlerMapping . It maps aController to /a/* , not /a/** , so only one level of the path hierarchy is accepted. And again, if you need full flexibility, use DefaultAnnotationHandlerMapping .

+2
source

I can verify that this is possible. Could you post fragments of your controller?

0
source

can you try below

@RequestMapping (value = "/ a / b / {c}", method = RequestMethod.GET)

 public ModelAndView show(@PathParam("c") String c) { ModelAndView modelAndView = new ModelAndView("A"); return modelAndView; } 
0
source

Source: https://habr.com/ru/post/1201038/


All Articles