Introduce common SimpleUrlHandlerMapping constructors

Prior to this commit, the SimpleUrlHandlerMapping classes in Spring MVC
and Spring Webflux only had default constructors. This lead to the fact
that users often had to explicitly invoke setUrlMap() and setOrder() on
the newly instantiated SimpleUrlHandlerMapping.

In order to simplify the programmatic setup of a SimpleUrlHandlerMapping
in common scenarios, this commit introduces the following constructors.

- SimpleUrlHandlerMapping()
- SimpleUrlHandlerMapping(Map<String, ?> urlMap)
- SimpleUrlHandlerMapping(Map<String, ?> urlMap, int order)

Closes gh-23362
This commit is contained in:
Sam Brannen
2019-07-28 17:50:44 +02:00
parent 0a822ddf2d
commit f53cdb8bd2
12 changed files with 113 additions and 76 deletions

View File

@@ -53,11 +53,9 @@ Then you can map it to a URL and add a `WebSocketHandlerAdapter`, as the followi
public HandlerMapping handlerMapping() {
Map<String, WebSocketHandler> map = new HashMap<>();
map.put("/path", new MyWebSocketHandler());
int order = -1; // before annotated controllers
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
mapping.setUrlMap(map);
mapping.setOrder(-1); // before annotated controllers
return mapping;
return new SimpleUrlHandlerMapping(map, order);
}
@Bean