I was trying to register certain URLs for a Filter when I noticed that there is a difference between /*
and /**
patterns.
@Bean
public FilterRegistrationBean tokenAuthenticationFilterBean() {
FilterRegistrationBean registration = new FilterRegistrationBean(tokenAuthenticationFilter);
registration.addUrlPatterns("/api/**","/ping","/api/*");
return registration;
}
What is the difference between these patterns?
Combine two patterns into a new pattern. Actually match the given path against the given pattern . Given a pattern and a full path, determine the pattern-mapped part. Given a pattern and a full path, extract the URI template variables.
Includes a chain of path elements for fast matching and accumulates computed state for quick comparison of patterns. PathPattern matches URL paths using the following rules: ? matches one character. * matches zero or more characters within a path segment.
A Spring MVC is a Java framework which is used to build web applications. It follows the Model-View-Controller design pattern.
Spring normally uses ant-style path matching patterns for URLs - if you look at the java docs for the AntPathMatcher you will see the explanation
The mapping matches URLs using the following rules: ? matches one character
* matches zero or more characters
** matches zero or more directories in a path
{spring:[a-z]+} matches the regexp [a-z]+ as a path variable named "spring"
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With