Skip to content

Dispatcher fails to invoke handler method when request method conflicts with request path [SPR-6978] #11643

@spring-projects-issues

Description

@spring-projects-issues

Andy Kriger opened SPR-6978 and commented

Here is a situation that causes a HandlerMethodInvocationException
java.lang.IllegalStateException: Could not find @PathVariable [type] in @RequestMapping

GET /foo/100 - loadEntity is called
POST /foo/100 - publish is called
GET /module/100 - loadModule is called
POST /module/100 - the exception is caused

Changing the path in either loadModule or publish (ex: loadModule as /q/module/{id}) fixes the problem

It looks like RequestMapping.method is not being prioritized over RequestMapping.value

@Controller
public class MyController
{ 
    @RequestMapping(value = "/{type}/{id}", method = RequestMethod.GET)
    public final Object loadEntity(@PathVariable final String type, @PathVariable final long id) { return type + "::" + id; }

    @RequestMapping(value = "/module/{id}", method = RequestMethod.GET) public final Object loadModule(@PathVariable final long id) {
        return ""+id;
    }

    @RequestMapping(value = "/{type}/{id}", method = RequestMethod.POST) public final Object publish(@PathVariable final String type,@PathVariable final long id) { return type + "::" + id; }
}

Affects: 3.0.1

Referenced from: commits 4c0744e

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions