Top Description Fields Constructors Methods
org.springframework.web.servlet.config.annotation

public Class PathMatchConfigurer

extends Object
Class Inheritance
Imports
java.util.LinkedHashMap, .Map, java.util.function.Predicate, org.springframework.lang.Nullable, org.springframework.util.AntPathMatcher, .PathMatcher, org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping, org.springframework.web.util.UrlPathHelper, org.springframework.web.util.pattern.PathPattern, .PathPatternParser

Configure path matching options. The options are applied to the following:
Authors
Brian Clozel, Rossen Stoyanchev
Since
4.0.3

Field Summary

Modifier and TypeField and Description
private PathMatcher
private PathPatternParser
private UrlPathHelper
private PathMatcher
private Map<String, Predicate<Class<?>>>
private PathPatternParser
private boolean
private Boolean
private Boolean
private Boolean
private UrlPathHelper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public PathMatchConfigurer
addPathPrefix(String
the prefix to apply
prefix
,
Predicate<Class<?>>
a predicate for matching controller types
predicate
)

Configure a path prefix to apply to matching controller methods.

public PathMatcher
protected PathMatcher
getPathMatcherOrDefault()

Return the configured PathMatcher or a default, shared instance otherwise.

protected Map<String, Predicate<Class<?>>>
public PathPatternParser
getPatternParser()

Return the PathPatternParser to use, if configured.

public PathPatternParser
getPatternParserOrDefault()

Return the configured PathPatternParser or a default, shared instance otherwise.

public UrlPathHelper
protected UrlPathHelper
getUrlPathHelperOrDefault()

Return the configured UrlPathHelper or a default, shared instance otherwise.

public Boolean
isUseRegisteredSuffixPatternMatch()
Deprecated as of 5.2.4, see deprecation note on setUseRegisteredSuffixPatternMatch(Boolean).

Whether to use registered suffixes for pattern matching.

public Boolean
isUseSuffixPatternMatch()
Deprecated as of 5.2.4, see deprecation note on setUseSuffixPatternMatch(Boolean).

Whether to use registered suffixes for pattern matching.

public Boolean
protected boolean
preferPathMatcher()

Whether to prefer PathMatcher.

public PathMatchConfigurer
setPathMatcher(PathMatcher pathMatcher)

Set the PathMatcher to use for String pattern matching.

public PathMatchConfigurer
setPatternParser(PathPatternParser
the parser to pre-parse patterns with
patternParser
)

Set the PathPatternParser to parse patterns with for URL path matching.

public PathMatchConfigurer
setUrlPathHelper(UrlPathHelper urlPathHelper)

Set the UrlPathHelper to use to resolve the mapping path for the application.

public PathMatchConfigurer
setUseRegisteredSuffixPatternMatch(Boolean registeredSuffixPatternMatch)
Deprecated as of 5.2.4.

Whether suffix pattern matching should work only against path extensions explicitly registered when you configure content negotiation.

public PathMatchConfigurer
setUseSuffixPatternMatch(Boolean suffixPatternMatch)
Deprecated as of 5.2.4.

Whether to use suffix pattern match (".*") when matching patterns to requests.

public PathMatchConfigurer
setUseTrailingSlashMatch(Boolean trailingSlashMatch)

Whether to match to URLs irrespective of the presence of a trailing slash.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultPathMatcherback to summary
private PathMatcher defaultPathMatcher
Annotations
@Nullable
defaultPatternParserback to summary
private PathPatternParser defaultPatternParser
Annotations
@Nullable
defaultUrlPathHelperback to summary
private UrlPathHelper defaultUrlPathHelper
Annotations
@Nullable
pathMatcherback to summary
private PathMatcher pathMatcher
Annotations
@Nullable
pathPrefixesback to summary
private Map<String, Predicate<Class<?>>> pathPrefixes
Annotations
@Nullable
patternParserback to summary
private PathPatternParser patternParser
Annotations
@Nullable
preferPathMatcherback to summary
private boolean preferPathMatcher
registeredSuffixPatternMatchback to summary
private Boolean registeredSuffixPatternMatch
Annotations
@Nullable
suffixPatternMatchback to summary
private Boolean suffixPatternMatch
Annotations
@Nullable
trailingSlashMatchback to summary
private Boolean trailingSlashMatch
Annotations
@Nullable
urlPathHelperback to summary
private UrlPathHelper urlPathHelper
Annotations
@Nullable

Constructor Detail

PathMatchConfigurerback to summary
public PathMatchConfigurer()

Method Detail

addPathPrefixback to summary
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:String

the prefix to apply

predicate:Predicate<Class<?>>

a predicate for matching controller types

Since
5.1
getPathMatcherback to summary
public PathMatcher getPathMatcher()
Annotations
@Nullable
getPathMatcherOrDefaultback to summary
protected PathMatcher getPathMatcherOrDefault()

Return the configured PathMatcher or a default, shared instance otherwise.

Since
5.3
getPathPrefixesback to summary
protected Map<String, Predicate<Class<?>>> getPathPrefixes()
Annotations
@Nullable
getPatternParserback to summary
public PathPatternParser getPatternParser()

Return the PathPatternParser to use, if configured.

Annotations
@Nullable
Since
5.3
getPatternParserOrDefaultback to summary
public PathPatternParser getPatternParserOrDefault()

Return the configured PathPatternParser or a default, shared instance otherwise.

Since
5.3.4
getUrlPathHelperback to summary
public UrlPathHelper getUrlPathHelper()
Annotations
@Nullable
getUrlPathHelperOrDefaultback to summary
protected UrlPathHelper getUrlPathHelperOrDefault()

Return the configured UrlPathHelper or a default, shared instance otherwise.

Since
5.3
isUseRegisteredSuffixPatternMatchback to summary
public Boolean isUseRegisteredSuffixPatternMatch()

Deprecated

as of 5.2.4, see deprecation note on setUseRegisteredSuffixPatternMatch(Boolean).

Whether to use registered suffixes for pattern matching.

Annotations
@Nullable
@Deprecated
isUseSuffixPatternMatchback to summary
public Boolean isUseSuffixPatternMatch()

Deprecated

as of 5.2.4, see deprecation note on setUseSuffixPatternMatch(Boolean).

Whether to use registered suffixes for pattern matching.

Annotations
@Nullable
@Deprecated
isUseTrailingSlashMatchback to summary
public Boolean isUseTrailingSlashMatch()

Deprecated

Annotations
@Nullable
@Deprecated
preferPathMatcherback to summary
protected boolean preferPathMatcher()

Whether to prefer PathMatcher. This is the case when either is true:

Since
6.0
setPathMatcherback to summary
public PathMatchConfigurer setPathMatcher(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.

setPatternParserback to summary
public PathMatchConfigurer setPatternParser(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:

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:PathPatternParser

the parser to pre-parse patterns with

Since
5.3
setUrlPathHelperback to summary
public PathMatchConfigurer setUrlPathHelper(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.

setUseRegisteredSuffixPatternMatchback to summary
public PathMatchConfigurer setUseRegisteredSuffixPatternMatch(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".

Annotations
@Deprecated
setUseSuffixPatternMatchback to summary
public PathMatchConfigurer setUseSuffixPatternMatch(Boolean suffixPatternMatch)

Deprecated

as of 5.2.4. See class-level note in RequestMappingHandlerMapping on the deprecation of path extension config options. As there is no replacement for this method, in 5.2.x it is necessary to set it to false. In 5.3 the default changes to false and use of this property becomes unnecessary.

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.

Annotations
@Deprecated
setUseTrailingSlashMatchback to summary
public PathMatchConfigurer setUseTrailingSlashMatch(Boolean trailingSlashMatch)

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.

Annotations
@Deprecated
since:6.0