【发布时间】:2015-08-13 21:15:04
【问题描述】:
我正在尝试将以下 URL 解析为我服务器上的相同资源:
http://myhost/website/content/css/theme.css
http://myhost/subsite/app/website/content/css/theme.css
一般来说:
http://myhost/{any non-/ string}/app/website/content/css/theme.css
以下配置成功解析:
http://myhost/website/content/css/theme.css
但顽固地拒绝解析任何 */app 网址:
@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("/")
}
这是怎么回事?
注意。
- servlet 上下文是 ROOT (/)。
- 所有内容都在 /src/main/webapp/ 中(即 /src/main/webapp/website/content/css/theme.css 存在)
【问题讨论】:
标签: spring spring-mvc