92

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?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
mpmp
  • 2,409
  • 4
  • 33
  • 46
  • Are you sure that `/resources/**` works in ``? – axtavt Sep 24 '12 at 17:18
  • As a side note, [org.springframework.js.resource.ResourceServlet](http://docs.spring.io/spring-webflow/docs/2.4.x/api/org/springframework/js/resource/ResourceServlet.html) is deprecated. From the [Spring Web Flow Reference Guide](http://docs.spring.io/spring-webflow/docs/current/reference/html/index.html): "Note that starting with version 3.0.4, the Spring Framework includes a replacement for the ResourceServlet (see the [Spring Framework documentation](http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources))." – informatik01 Feb 25 '14 at 19:30

1 Answers1

63

This is a path pattern that is used in Apache Ant library. Spring team implements it and uses it throughout the framework.


Back to your problem. According to the Javadoc for AntPathMatcher, it only has 3 rules:

  1. ? matches one character
  2. * matches zero or more characters
  3. ** matches zero or more 'directories' in a path

UPDATE 2022

In the latest Spring Framework versions there is a forth rule:

  1. {spring:[a-z]+} matches the regexp [a-z]+ as a path variable named "spring"

See the details in the latest (as of now) Spring Framework version 5 Javadoc: AntPathMathcer.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Rangi Lin
  • 9,303
  • 6
  • 45
  • 71
  • 2
    Is it possible for `*` to match what `**` can't? – Alexander Suraphel Aug 03 '14 at 16:56
  • 4
    Note that Springs' AntPathMatcher contains bugs: it isn't fully conform the Ant Pattern Style. Example: `**/*.css` won't work for paths that start with a `/`, while it should according to Ant Style conventions. – Devabc Jun 12 '15 at 09:52