Continuing the discussion from #5004

@michaelkrog Could you create a new issue with a sample project showing the problem


Sure.. https://github.com/michaelkrog/spring-boot-webmvc-versioning-demo

Maybe there is a better way to do this, that I don't know of. But what I am trying to do is to add multiple (versioned) controllers with same RequestMapping. Only difference between them is a custom annotation that via a Semver range defines what api-version it belongs to.

ControllerV1_0: https://github.com/michaelkrog/spring-boot-webmvc-versioning-demo/blob/master/src/main/java/com/example/demo/ControllerV1_0.java

ControllerV1_1: https://github.com/michaelkrog/spring-boot-webmvc-versioning-demo/blob/master/src/main/java/com/example/demo/ControllerV1_1.java

ApiRequestMapping (Custom RequestMappingHandlerMapping): https://github.com/michaelkrog/spring-boot-webmvc-versioning-demo/blob/master/src/main/java/com/example/demo/ApiVersionedRequestMapping.java

I can choose the version I want served via Api-Version header fx. curl http://server/version -H 'Api-Version:1.0.0' (ControllerV1_0) curl http://server/version -H 'Api-Version:1.1.0' (ControllerV1_1)

If I register my Custom RequestMappingHandlerMapping via WebRegistrations, then I get a second RequestMappingHandlerMapping instantiated, and the first one created by DelegatingWebMvcConfiguration will complain that my RequestMapping's are ambiguous, because it doesnt know about my custom RequestCondition.

Comment From: michaelkrog

Just to remove any confusion: The project I refered to works as it should. It just does'nt use WebRegistrations. It extends from DelegatingWebMvcConfiguration like this instead:

// @EnableWebMvc <- Remove annotation and extend from DelegatingWebMvcConfiguration directly
public class WebConfig extends DelegatingWebMvcConfiguration {
    @Override
    public RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
        return new CustomRequestMappingHandlerMapping();
    }
}

And auto-config seems to work still.

Comment From: bclozel

@michaelkrog I've just sent you a PR on the sample project.

I've applied the exact recipe I provided in a previous comment and it seems to work (I've added a test case in my PR to demonstrate that).

There must be a misunderstanding here since:

I guess when you tried to apply that you still kept the DelegatingWebMvcConfiguration around, which in this case still disables all Spring Boot auto-configuration for Spring MVC. Spring MVC was still working, but with Spring Framework's defaults. You could see that by changing any spring.mvc.* configuration property: it won't be taken into account in this case.

I'm closing this issue for now as it seems everything is working as expected. Feel free to reopen this issue if I've missed something.

Thanks!

Comment From: michaelkrog

That makes sense. Somehow I had picked up that @EnableMvc (and DelegatingWebMvcConfiguration) was required in Spring Boot to make controllers etc initialize.

Thx!