Issue
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?
Solution
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"
Answered By - rhinds
Answer Checked By - Willingham (JavaFixing Volunteer)