DATAREST-1540 - Tweak HandlerMapping setup to retain compatibility with 5.3.

Turns out that Spring Boot references DelegatingHandlerMapping from its metrics integration to pick up the HandlerMappings delegated to. Reintroduced the relevant type in deprecated form and also let it implement Iterable<HandlerMapping> so that client code can be moved to generally check for HandlerMappings implementing that and pick up the delegates that way.
This commit is contained in:
Oliver Drotbohm
2020-07-29 12:27:31 +02:00
parent 5f2703336a
commit 15b8d598bd
2 changed files with 51 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ import lombok.Getter;
import lombok.NonNull;
import lombok.Value;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@@ -43,7 +44,8 @@ import org.springframework.web.util.pattern.PathPatternParser;
* @author Oliver Gierke
* @soundtrack Benny Greb - Stabila (Moving Parts)
*/
class DelegatingHandlerMapping extends AbstractHandlerMapping implements MatchableHandlerMapping {
class DelegatingHandlerMapping extends AbstractHandlerMapping
implements org.springframework.data.rest.webmvc.support.DelegatingHandlerMapping {
private final @Getter List<HandlerMapping> delegates;
@@ -70,6 +72,15 @@ class DelegatingHandlerMapping extends AbstractHandlerMapping implements Matchab
.forEach(it -> it.setPatternParser(parser));
}
/*
* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<HandlerMapping> iterator() {
return delegates.iterator();
}
/*
* (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder()

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.rest.webmvc.support;
import java.util.List;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.handler.MatchableHandlerMapping;
/**
* A {@link HandlerMapping} that exposes its delegates.
*
* @author Oliver Drotbohm
* @deprecated since 3.4. Prefer handling {@link HandlerMapping}s that implement {@link Iterable} of
* {@link HandlerMapping} and consume the delegates that way.
*/
@Deprecated
public interface DelegatingHandlerMapping extends MatchableHandlerMapping, Iterable<HandlerMapping> {
/**
* Returns all delegate {@link HandlerMapping}s. Prefer simply iterating over this instance itself.
*
* @return will never be {@literal null}.
*/
List<HandlerMapping> getDelegates();
}