Affects: spring-webmvc 6.0.4

I use MvcUriComponentsBuilder.fromMethodCall(...) to compute paths to controller endpoints and include them in view models. In my controllers, the path usually is configured on the controller level (via @RequestMapping annotation). The controller methods are annotated with empty @GetMapping, @PostMapping, or similar annotations.

After upgrading to spring-boot 3 (spring 6) the computed paths do not work anymore, because they contain a trailing slash, which is no longer accepted due to the deactivated/deprecated trailing slash matching configuration in spring 6.

Debugging into the MvcUriComponentsBuilder I found the following method, which seems to cause this (now incompatible) behavior:

    private static String getMethodMapping(Method method) {
        Assert.notNull(method, "'method' must not be null");
        RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
        if (requestMapping == null) {
            throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
        }
        String[] paths = requestMapping.path();
        if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) {
            return "/";
        }
        if (paths.length > 1 && logger.isTraceEnabled()) {
            logger.trace("Using first of multiple paths on " + method.toGenericString());
        }
        return paths[0];
    }

In my case, requestMapping.path() returns an empty array (which seems to be correct because the method level request mapping contains no path). But this leads to the method returning a single slash, which is added to the path that is taken from the controller level annotation (in the fromMethodInternal method).

When I move the path configuration into the method level annotations, everything works fine.