Spring:/** 和 /* 在路径方面的差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12569308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring: Difference of /** and /* with regards to paths
提问by mpmp
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 3 项目。我试图添加一个 .swf 使用
<spring:url var="flashy" value="/resources/images/flash.swf"/>
<spring:url var="flashy" value="/resources/images/flash.swf"/>
With my web.xml's ResourceServlet looking like
我的 web.xml 的 ResourceServlet 看起来像
<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.
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 imagesfolder were accessed but how come my .swf was "protected"?
我发现这真的很奇怪,因为我在images文件夹中的所有图像都被访问过,但是我的 .swf 怎么被“保护”了?
Afterwards, I decided to change the /resources/*to /resources/**and it finally worked. My question is... why?
之后,我决定将其更改/resources/*为/resources/**,它终于奏效了。我的问题是……为什么?
回答by Rangi Lin
This is a path pattern that used in Apache ant, spring team implement it and use it throughout the framework.
这是一个在 中使用的路径模式Apache ant,spring 团队实现它并在整个框架中使用它。
For reference, see javadoc of AntPathMatcher(newestjavadoc seems to have problem, so I link an old one).
作为参考,请参阅AntPathMatcher 的javadoc (最新的javadoc 似乎有问题,所以我链接了一个旧的)。
Back to your problem, according to the document, it only have 3 rules:
回到你的问题,根据文档,它只有3条规则:
?matches one character*matches zero or more characters**matches zero or more 'directories' in a path
?匹配一个字符*匹配零个或多个字符**匹配路径中的零个或多个“目录”

