我正在尝试将我的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进行了解决,并将文件内容写入响应流,但是为了提供静态文件,这似乎很愚蠢。
答案 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。
在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>
作为处理程序模式。