We have a servlet defined in our web.xml:
<servlet>
<servlet-name>foo</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>foo</servlet-name>
<url-pattern>/foo/*</url-pattern>
</servlet-mapping>
In our controller class, we use both @RequestMapping, and @RestController.
package com.example.foo;
@RestController("/foo/bar/v1")
public class Baz {
@RequestMapping(value="/bar/v1/abc" /* ... */)
public String doXyz() {
Now I know Spring documentation for RequestMapping says
When used at the type level, all mappings at the method level inherit this primary mapping, narrowing it down for a particular handler method.
, @RequestMapping("/foo") , , , . , @RequestMapping("/foo/bar/v1") , @RestController, /foo/bar/v1/bar/v1/abc - /foo/bar/v1/abc, . ?
, -, @RestController("/foo/bar/v1") , @RequestMapping("/foo/bar/v1") - - ?
, ? /foo/ web.xml?
, , :
MvcResult result = mockMvc.perform(
get("/foo/bar/v1")
.accept(MediaType.APPLICATION_JSON_VALUE)
, ,
- web.xml,
/foo @RequestMapping("bar/v1") @RestController("/foo/bar/v1").
, ,
javax.servlet.ServletException: [com.example.foo.Baz@5b800468]: DispatcherServlet HandlerAdapter,
, ( @WebAppConfiguration):
<context:annotation-config/>
<mvc:annotation-driven/>
<context:component-scan base-package="com.example.foo" />
web.xml ?