在我的Spring Web Application项目中,我已经配置了一个mvc:resources标签来排除CSS、JS、图片……从DispatcherServlet映射
现在我还需要排除一个foobar.txt,它和其他静态资源一样被放在/webapp目录下,但是...它不起作用。
下面是我的代码片段
<mvc:resources mapping="/assets/**" location="/assets/" />
<mvc:resources mapping="/foobar.txt" location="/foobar.txt" />我的文件夹结构是:
/webapp
/webapp/assets
/webapp/foobar.txt
/webapp/...看起来第一个mvc:resources标签(assets)可以工作,但第二个(version.txt)不行。
我得到了一个404页。
这就是控制台日志的区别。
2018-07-12 13:58:25,093 DEBUG [http-nio-8080-exec-6] (DispatcherServlet.java:845) - DispatcherServlet with name 'dispatcher' processing GET request for [/mscbackend/foobar.txt]
2018-07-12 13:58:25,093 DEBUG [http-nio-8080-exec-6] (AbstractHandlerMethodMapping.java:297) - Looking up handler method for path /foobar.txt
2018-07-12 13:58:25,096 DEBUG [http-nio-8080-exec-6] (AbstractHandlerMethodMapping.java:305) - Did not find handler method for [/foobar.txt]
2018-07-12 13:58:25,097 DEBUG [http-nio-8080-exec-6] (AbstractUrlHandlerMapping.java:123) - Mapping [/foobar.txt] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/foobar.txt]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@66894a78]]] and 1 interceptor
2018-07-12 14:08:27,165 DEBUG [http-nio-8080-exec-7] (DispatcherServlet.java:845) - DispatcherServlet with name 'dispatcher' processing GET request for [/mscbackend/assets/css/style.css]
2018-07-12 14:08:27,165 DEBUG [http-nio-8080-exec-7] (AbstractHandlerMethodMapping.java:297) - Looking up handler method for path /assets/css/style.css
2018-07-12 14:08:27,169 DEBUG [http-nio-8080-exec-7] (AbstractHandlerMethodMapping.java:305) - Did not find handler method for [/assets/css/style.css]
2018-07-12 14:08:27,169 DEBUG [http-nio-8080-exec-7] (AbstractUrlHandlerMapping.java:168) - Matching patterns for request [/assets/css/style.css] are [/assets/**]奇怪的是,在另一个类似的项目中,相同的配置工作起来没有问题。
提前感谢您的支持。
发布于 2018-07-13 12:37:33
请尝试下面的配置。
<mvc:resources location="/", mapping="/resources/**"/>或者,如果您想为特定位置提供类路径,请使用下面的方法。
<mvc:resources location="/, classpath:/META-INF/web-resources/" mapping="/resources/**"/>发布于 2018-07-13 22:13:24
尝试此配置。
<mvc:resources mapping="/resources/**" location="/resources/" />我不知道为什么,但有时它是有效的。你可以试一试。
https://stackoverflow.com/questions/51307701
复制相似问题