forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve PathMatcher/PatternParser XML configuration
Prior to this commit, the MVC namespace for the XML Spring configuration model would use the `PathMatcher` bean instance when provided like this: ``` <bean id="pathMatcher" class="org.springframework.util.AntPathMatcher"/> <mvc:annotation-driven> <mvc:path-matching path-matcher="pathMatcher"/> </mvc:annotation-driven> <mvc:resources mapping="/resources/**" location="classpath:/static/"/> ``` With this configuration, the handler mapping for annotated controller would use the given `AntPathMatcher` instance but the handler mapping for resources would still use the default, which is `PathPatternParser` since 6.0. This commit ensures that when a custom `path-matcher` is defined, it's consistently used for all MVC handler mappings as an alias to the well-known bean name. This allows to use `AntPathMatcher` consistently while working on a migration path to `PathPatternParser` This commit also adds a new XML attribute to the path matching configuration that makes it possible to use a custom `PathPatternParser` instance: ``` <bean id="patternParser" class="org.springframework.web.util.pattern.PathPatternParser"/> <mvc:annotation-driven> <mvc:path-matching pattern-parser="patternParser"/> </mvc:annotation-driven> ``` Closes spring-projectsgh-34102 See spring-projectsgh-34064
- Loading branch information
Showing
9 changed files
with
176 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...est/resources/org/springframework/web/servlet/config/mvc-config-custom-pattern-parser.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> | ||
|
||
<bean id="patternParser" class="org.springframework.web.util.pattern.PathPatternParser"/> | ||
|
||
<mvc:annotation-driven> | ||
<mvc:path-matching pattern-parser="patternParser"/> | ||
</mvc:annotation-driven> | ||
|
||
<mvc:view-controller path="/foo"/> | ||
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/"/> | ||
|
||
</beans> |
17 changes: 17 additions & 0 deletions
17
...t/resources/org/springframework/web/servlet/config/mvc-config-deprecated-path-matcher.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"> | ||
|
||
<bean id="pathMatcher" class="org.springframework.util.AntPathMatcher"/> | ||
|
||
<mvc:annotation-driven> | ||
<mvc:path-matching path-matcher="pathMatcher"/> | ||
</mvc:annotation-driven> | ||
|
||
<mvc:view-controller path="/foo"/> | ||
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/"/> | ||
|
||
</beans> |