Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between /* and /** pattern in Spring boot?

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?

like image 923
amitection Avatar asked Nov 30 '16 10:11

amitection


People also ask

What is the use of AntPathMatcher?

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.

What is path pattern in Spring boot?

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.

Which design pattern is used in Spring MVC?

A Spring MVC is a Java framework which is used to build web applications. It follows the Model-View-Controller design pattern.


1 Answers

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

like image 125
rhinds Avatar answered Sep 22 '22 05:09

rhinds