Package org.springframework.web.servlet.config.annotation

# Class PathMatchConfigurer

java.lang.Object
org.springframework.web.servlet.config.annotation.PathMatchConfigurer

public class PathMatchConfigurer extends Object
Configure path matching options. The options are applied to the following:

- `WebMvcConfigurationSupport.requestMappingHandlerMapping(org.springframework.web.accept.ContentNegotiationManager, org.springframework.format.support.FormattingConversionService, org.springframework.web.servlet.resource.ResourceUrlProvider)`
- `WebMvcConfigurationSupport.viewControllerHandlerMapping(org.springframework.format.support.FormattingConversionService, org.springframework.web.servlet.resource.ResourceUrlProvider)`
- `WebMvcConfigurationSupport.beanNameHandlerMapping(org.springframework.format.support.FormattingConversionService, org.springframework.web.servlet.resource.ResourceUrlProvider)`
- `WebMvcConfigurationSupport.routerFunctionMapping(org.springframework.format.support.FormattingConversionService, org.springframework.web.servlet.resource.ResourceUrlProvider)`
- `WebMvcConfigurationSupport.resourceHandlerMapping(org.springframework.web.accept.ContentNegotiationManager, org.springframework.format.support.FormattingConversionService, org.springframework.web.servlet.resource.ResourceUrlProvider)`

Since:
  4.0.3
Author:
  Brian Clozel, Rossen Stoyanchev

## Constructor Summary

Constructors
Constructor
Description
`PathMatchConfigurer()`

## Method Summary

Modifier and Type
Method
Description
`PathMatchConfigurer`
`addPathPrefix(String prefix, Predicate<Class<?>> predicate)`
Configure a path prefix to apply to matching controller methods.
`org.springframework.util.PathMatcher`
`getPathMatcher()`
`protected org.springframework.util.PathMatcher`
`getPathMatcherOrDefault()`
Return the configured PathMatcher or a default, shared instance otherwise.
`protected Map<String,Predicate<Class<?>>>`
`getPathPrefixes()`
`org.springframework.web.util.pattern.PathPatternParser`
`getPatternParser()`
Return the `PathPatternParser` to use, if configured.
`org.springframework.web.util.pattern.PathPatternParser`
`getPatternParserOrDefault()`
Return the configured PathPatternParser or a default, shared instance otherwise.
`org.springframework.web.util.UrlPathHelper`
`getUrlPathHelper()`
`protected org.springframework.web.util.UrlPathHelper`
`getUrlPathHelperOrDefault()`
Return the configured UrlPathHelper or a default, shared instance otherwise.
`Boolean`
`isUseRegisteredSuffixPatternMatch()`
Deprecated.
as of 5.2.4, see deprecation note on `setUseRegisteredSuffixPatternMatch(Boolean)`.
`Boolean`
`isUseSuffixPatternMatch()`
Deprecated.
as of 5.2.4, see deprecation note on `setUseSuffixPatternMatch(Boolean)`.
`Boolean`
`isUseTrailingSlashMatch()`
Deprecated.
`protected boolean`
`preferPathMatcher()`
Whether to prefer `PathMatcher`.
`PathMatchConfigurer`
`setPathMatcher(org.springframework.util.PathMatcher pathMatcher)`
Set the PathMatcher to use for String pattern matching.
`PathMatchConfigurer`
`setPatternParser(org.springframework.web.util.pattern.PathPatternParser patternParser)`
Set the `PathPatternParser` to parse `patterns` with for URL path matching.
`PathMatchConfigurer`
`setUrlPathHelper(org.springframework.web.util.UrlPathHelper urlPathHelper)`
Set the UrlPathHelper to use to resolve the mapping path for the application.
`PathMatchConfigurer`
`setUseRegisteredSuffixPatternMatch(Boolean registeredSuffixPatternMatch)`
Deprecated.
as of 5.2.4.
`PathMatchConfigurer`
`setUseSuffixPatternMatch(Boolean suffixPatternMatch)`
Deprecated.
as of 5.2.4.
`PathMatchConfigurer`
`setUseTrailingSlashMatch(Boolean trailingSlashMatch)`
Deprecated.
as of 6.0, see `PathPatternParser.setMatchOptionalTrailingSeparator(boolean)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### PathMatchConfigurer

public PathMatchConfigurer()

## Method Details

### setPatternParser

public PathMatchConfigurer setPatternParser(@Nullable org.springframework.web.util.pattern.PathPatternParser patternParser)
Set the `PathPatternParser` to parse `patterns` with for URL path matching. Parsed patterns provide a more modern and efficient alternative to String path matching via `AntPathMatcher`.

Note: This property is mutually exclusive with the following other, `AntPathMatcher` related properties:

- `setUseSuffixPatternMatch(Boolean)`
- `setUseRegisteredSuffixPatternMatch(Boolean)`
- `setUrlPathHelper(UrlPathHelper)`
- `setPathMatcher(PathMatcher)`

By default, as of 6.0, a `PathPatternParser` with default settings is used, which enables parsed `patterns`. Set this property to `null` to fall back on String path matching via `AntPathMatcher` instead, or alternatively, setting one of the above listed `AntPathMatcher` related properties has the same effect.

Parameters:
  `patternParser` - the parser to pre-parse patterns with
Since:
  5.3

### setUseTrailingSlashMatch

@Deprecated(since="6.0") public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch)
Deprecated.
as of 6.0, see `PathPatternParser.setMatchOptionalTrailingSeparator(boolean)`
Whether to match to URLs irrespective of the presence of a trailing slash. If enabled a method mapped to "/users" also matches to "/users/".

The default was changed in 6.0 from `true` to `false` in order to support the deprecation of the property.

### addPathPrefix

public PathMatchConfigurer addPathPrefix(String prefix, Predicate<Class<?>> predicate)
Configure a path prefix to apply to matching controller methods.

Prefixes are used to enrich the mappings of every `@RequestMapping` method whose controller type is matched by the corresponding `Predicate`. The prefix for the first matching predicate is used.

Consider using `HandlerTypePredicate` to group controllers.

Parameters:
  `prefix` - the prefix to apply
  `predicate` - a predicate for matching controller types
Since:
  5.1

### setUseSuffixPatternMatch

@Deprecated public PathMatchConfigurer setUseSuffixPatternMatch(@Nullable Boolean suffixPatternMatch)
Deprecated.
as of 5.2.4. See class-level note in `RequestMappingHandlerMapping` on the deprecation of path extension config options.
Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled a method mapped to "/users" also matches to "/users.*".

Note: This property is mutually exclusive with `setPatternParser(PathPatternParser)`. If set, it enables use of String path matching, unless a `PathPatternParser` is also explicitly set in which case this property is ignored.

By default this is set to `false`.

### setUseRegisteredSuffixPatternMatch

@Deprecated public PathMatchConfigurer setUseRegisteredSuffixPatternMatch(@Nullable Boolean registeredSuffixPatternMatch)
Deprecated.
as of 5.2.4. See class-level note in `RequestMappingHandlerMapping` on the deprecation of path extension config options.
Whether suffix pattern matching should work only against path extensions explicitly registered when you `configure content negotiation`. This is generally recommended to reduce ambiguity and to avoid issues such as when a "." appears in the path for other reasons.

Note: This property is mutually exclusive with `setPatternParser(PathPatternParser)`. If set, it enables use of String path matching, unless a `PathPatternParser` is also explicitly set in which case this property is ignored.

By default this is set to "false".

### setUrlPathHelper

public PathMatchConfigurer setUrlPathHelper(org.springframework.web.util.UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use to resolve the mapping path for the application.

Note: This property is mutually exclusive with `setPatternParser(PathPatternParser)`. If set, it enables use of String path matching, unless a `PathPatternParser` is also explicitly set in which case this property is ignored.

By default this is an instance of `UrlPathHelper` with default settings.

### setPathMatcher

public PathMatchConfigurer setPathMatcher(org.springframework.util.PathMatcher pathMatcher)
Set the PathMatcher to use for String pattern matching.

Note: This property is mutually exclusive with `setPatternParser(PathPatternParser)`. If set, it enables use of String path matching, unless a `PathPatternParser` is also explicitly set in which case this property is ignored.

By default this is an instance of `AntPathMatcher` with default settings.

### preferPathMatcher

protected boolean preferPathMatcher()
Whether to prefer `PathMatcher`. This is the case when either is true:

- `PathPatternParser` is explicitly set to `null`.
- `PathPatternParser` is not explicitly set, and a `PathMatcher` related option is explicitly set.

Since:
  6.0

### getPatternParser

@Nullable public org.springframework.web.util.pattern.PathPatternParser getPatternParser()
Return the `PathPatternParser` to use, if configured.

Since:
  5.3

### isUseTrailingSlashMatch

@Nullable @Deprecated public Boolean isUseTrailingSlashMatch()
Deprecated.

### getPathPrefixes

@Nullable protected Map<String,Predicate<Class<?>>> getPathPrefixes()

### isUseRegisteredSuffixPatternMatch

@Nullable @Deprecated public Boolean isUseRegisteredSuffixPatternMatch()
Deprecated.
as of 5.2.4, see deprecation note on `setUseRegisteredSuffixPatternMatch(Boolean)`.
Whether to use registered suffixes for pattern matching.

### isUseSuffixPatternMatch

@Nullable @Deprecated public Boolean isUseSuffixPatternMatch()
Deprecated.
as of 5.2.4, see deprecation note on `setUseSuffixPatternMatch(Boolean)`.
Whether to use registered suffixes for pattern matching.

### getUrlPathHelper

@Nullable public org.springframework.web.util.UrlPathHelper getUrlPathHelper()

### getPathMatcher

@Nullable public org.springframework.util.PathMatcher getPathMatcher()

### getUrlPathHelperOrDefault

protected org.springframework.web.util.UrlPathHelper getUrlPathHelperOrDefault()
Return the configured UrlPathHelper or a default, shared instance otherwise.

Since:
  5.3

### getPathMatcherOrDefault

protected org.springframework.util.PathMatcher getPathMatcherOrDefault()
Return the configured PathMatcher or a default, shared instance otherwise.

Since:
  5.3

### getPatternParserOrDefault

public org.springframework.web.util.pattern.PathPatternParser getPatternParserOrDefault()
Return the configured PathPatternParser or a default, shared instance otherwise.

Since:
  5.3.4