Ambiguous mapping detected using @RequestMapping class level URL

I get the following exception if I use multilevel URLs in a class, for example @RequestMapping("/api/v0.1"):

java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'userController'
bean method getUsers()|to {[/api/v0.1]}: There is already 'userController' bean
method getUser(java.lang.String) mapped.

This is similar to method level comparisons, not taken into account at all.
But this is normal, if I put it @RequestMapping("/api"), that is, I will delete the part /v0.1.

Here is the configuration divided by the minimum case:

@Controller
@RequestMapping("/api/v0.1")
public class UserController {   

    @RequestMapping(value = "/users")
    @ResponseBody
    public List<User> getUsers() {
        return null;
    }

    @RequestMapping(value = "/users/{username}")
    @ResponseBody
    public User getUser(@PathVariable String username) {
        return null;
    }
}

web.xml

<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

servlet-context.xml:

<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />

<!-- Forwards requests to the "/" resource to the "welcome" view -->
<mvc:view-controller path="/" view-name="home"/>    

<!-- Handles HTTP GET requests for /assets/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
<mvc:resources mapping="/assets/**" location="/assets/" />

I am using spring 3.1. I also tried setting the property alwaysUseFullPathto true for the RequestMappingHandlerMappingbean, but that did not change the situation.

+5
source share
2 answers

- , , , "v0.1" org.springframework.util.AntPathMatcher, URI, . "file.extension", - @PathVariable .

, Spring MVC, , -

1. "v0.1" RequestMapping Controller , v0_1

2. :

@Controller
@RequestMapping("/api")
public class UserController {   

    @RequestMapping(value = "/v0.1/users")
    @ResponseBody
    public List<User> getUsers() {
        return null;
    }

    @RequestMapping(value = "/v0.1/users/{username}")
    @ResponseBody
    public User getUser(@PathVariable String username) {
        return null;
    }
}
+2

@RequestMapping(value = "/{version:.*}/users") "."

0

All Articles