Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring: Difference of /** and /* with regards to paths

What's the difference between two asterisks instead of one asterisk when we refer to paths?

Earlier I was debugging my Spring 3 project. I was trying to add a .swf using

<spring:url var="flashy" value="/resources/images/flash.swf"/>

With my web.xml's ResourceServlet looking like

<servlet-name>Resource Servlet </servlet-name> <url-pattern>/resources/*</url-pattern> 

But unfortunately I was getting this error:

WARN org.springframework.js.resources.ResourceServlet - An attempt to access a protected resource at /images/flash.swf was disallowed.

I found it really strange since all my images in the images folder were accessed but how come my .swf was "protected"?

Afterwards, I decided to change the /resources/* to /resources/** and it finally worked. My question is... why?

like image 944
mpmp Avatar asked Sep 24 '12 16:09

mpmp


People also ask

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.

What is ANT path matcher?

public class AntPathMatcher extends java.lang.Object implements PathMatcher. PathMatcher implementation for Ant-style path patterns. Part of this mapping code has been kindly borrowed from Apache Ant.

What is Spring Web MVC?

A Spring MVC is a Java framework which is used to build web applications. It follows the Model-View-Controller design pattern. It implements all the basic features of a core spring framework like Inversion of Control, Dependency Injection.


1 Answers

This is a path pattern that used in Apache ant, spring team implement it and use it throughout the framework.

For reference, see javadoc of AntPathMatcher (newest javadoc seems to have problem, so I link an old one).

Back to your problem, according to the document, it only have 3 rules:

  1. ? matches one character
  2. * matches zero or more characters
  3. ** matches zero or more 'directories' in a path
like image 80
Rangi Lin Avatar answered Oct 01 '22 10:10

Rangi Lin