3

I am trying to add support in our iOS app for Universal Links. So, our server needs to serve up a json file at the path /.well-known/apple-app-site-association. I created the file with filename apple-app-site-association in the folder src/main/resources/well-known/ and added the following to our application config:

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry)
{
    registry.addResourceHandler(".well-known/**").addResourceLocations("classpath:/well-known/");
}

However, this results in a 404 from the server. After trying many different things, I found that if I took the dot out like this:

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry)
{
    registry.addResourceHandler("well-known/**").addResourceLocations("classpath:/well-known/");
}

and navigated to /well-known/apple-app-site-association, it worked just fine. However, it needs to have the . in the URL.

Is there some way I can make this work? We are using Spring 4.3.7 and Spring Boot 1.4.5.

dnc253
  • 39,967
  • 41
  • 141
  • 157

1 Answers1

2

While digging into this more, I saw the in the Javadoc for addResourceHandler the following:

Patterns like "/static/**" or "/css/{filename:\\w+\\.css}"} are allowed.

So, I updated the mapping to look like the following:

registry.addResourceHandler("{filename:\\.well-known}/**").addResourceLocations("classpath:/well-known/");

After this change, things worked as expected. I found that it doesn't matter what is put before the colon, so this is what I finally ended up with:

registry.addResourceHandler("{wellKnownFolder:\\.well-known}/**").addResourceLocations("classpath:/well-known/");
dnc253
  • 39,967
  • 41
  • 141
  • 157