[英]Spring MVC resource mapping with dot in the URL
我正在嘗試在我們的iOS應用程序中添加對Universal Links的支持 。 因此,我們的服務器需要在/.well-known/apple-app-site-association
路徑下提供一個json文件。 我在src/main/resources/well-known/
文件夾中創建了文件src/main/resources/well-known/
apple-app-site-association
的文件,並將以下內容添加到我們的應用程序配置中:
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry)
{
registry.addResourceHandler(".well-known/**").addResourceLocations("classpath:/well-known/");
}
但是,這導致服務器發出404。 在嘗試了許多不同的東西之后,我發現如果我像這樣將點取出來:
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry)
{
registry.addResourceHandler("well-known/**").addResourceLocations("classpath:/well-known/");
}
並導航到/well-known/apple-app-site-association
,效果很好。 但是,它需要具有.
在網址中。
有什么辦法可以使這項工作嗎? 我們正在使用Spring 4.3.7和Spring Boot 1.4.5。
在深入研究這一點時,我在Javadoc中看到了addResourceHandler
的以下內容:
Patterns like "/static/**" or "/css/{filename:\\\\w+\\\\.css}"} are allowed.
因此,我將映射更新為如下所示:
registry.addResourceHandler("{filename:\\.well-known}/**").addResourceLocations("classpath:/well-known/");
更改之后,一切按預期進行。 我發現放在冒號前沒關系,這就是我最終得到的結果:
registry.addResourceHandler("{wellKnownFolder:\\.well-known}/**").addResourceLocations("classpath:/well-known/");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.