Reputation: 15788
I'm try to make the following URLs resolve to the same resources on my server:
http://myhost/website/content/css/theme.css
http://myhost/subsite/app/website/content/css/theme.css
and generically:
http://myhost/{any non-/ string}/app/website/content/css/theme.css
The following config successfully resolves:
http://myhost/website/content/css/theme.css
but stubbornly refused to resolve any */app URLs:
@Configuration
@EnableWebMvc
class WebMVCConfig extends WebMvcConfigurerAdapter {
override def addResourceHandlers(registry: ResourceHandlerRegistry): Unit = {
// servlet context URL path pattern --> webapp_relative_path
registry.addResourceHandler("/css/**").addResourceLocations("/css/")
registry.addResourceHandler("/js/**").addResourceLocations("/js/")
registry.addResourceHandler("/website/**").addResourceLocations("/website/")
registry.addResourceHandler("/index.html").addResourceLocations("/index.html")
// subsite redirects
registry.addResourceHandler("/*/app/index.html").addResourceLocations("/index.html")
registry.addResourceHandler("/*/app/website/**").addResourceLocations("/website/")
registry.addResourceHandler("/*/app/css/**").addResourceLocations("/css/")
registry.addResourceHandler("/*/app/js/**").addResourceLocations("/js/")
registry.addResourceHandler("/*/app/**").addResourceLocations("/")
}
What's up with that?
NB.
Upvotes: 0
Views: 751
Reputation: 467
I had the same problem and found that this seems to be due to a bad implementation of ant-style pattern matching in Spring, where preceding '/' don't work.
Try this:
registry.addResourceHandler("*/app/**").addResourceLocations("/")
Find my full answer in:
Spring boot static resources mapping ant matchers with ResourceHandlerRegistry
Upvotes: 1