Spring无法找到ResourceHandler映射的静态资源

时间:2017-06-29 17:36:35

标签: java spring spring-mvc

我正在尝试将我的Spring Boot MVC应用程序配置为在static\recordings目录中的resources下提供一些音频文件。

我添加了以下映射

public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/recordings/**.wav", "/recordings/**.mp3").addResourceLocations("/static/recordings/");
}

但是,请求:

/recordings/general/en/en-general-choose-language.wav
static/recordings/general/en/en-general-choose-language.wav

给出一个404,在日志中显示(当然根据路径稍微调整):

Looking up handler method for path /recordings/general/en/en-general-choose-language.wav
Did not find handler method for [/recordings/general/en/en-general-choose-language.wav]

我对Controller进行了解决,并将文件内容写入响应流,但是为了提供静态文件,这似乎很愚蠢。

1 个答案:

答案 0 :(得分:0)

ResourceHandlerRegistry#addResourceHandler的文档说明如下:http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.html#addResourceHandler-java.lang.String...-

  

" / static / **"或" / css / {filename:\ w + \。css}"被允许。有关语法的详细信息,请参阅AntPathMatcher。

http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html

在AntPathMatcher的描述中,我们找到了一个符合您需求的示例:

  

org / springframework / ** / * .jsp - 匹配org / springframework路径下的所有.jsp文件

因此,请尝试<xsl:template match="/root"> <attachments> <xsl:for-each select="node()[starts-with(name(), 'PHOTO')]"> <xsl:sort select="name()" /> <!-- name() as key --> <image><xsl:value-of select="." /></image> </xsl:for-each> </attachments> </xsl:template> 作为处理程序模式。