Spring 4 - addResourceHandlers 未解析静态资源
我的maven spring项目目录结构如下所示。我正在使用基于Spring-4注释的配置。我配置了如下资源。我尝试了许多Stackoverflow问题和其他网站中建议的方法
http://imwill.com/spring-mvc-4-add-static-resources-by-annotation/#.U5GZlXKs9i4
但是 jsp 文件无法加载资源,所有静态内容请求都返回 404 错误。我在jsp中尝试了这些东西,
<link href="resources/css/bootstrap.css" rel="stylesheet" media="screen">
<link href="/resources/css/bootstrap.css" rel="stylesheet" media="screen">
<link href="css/bootstrap.css" rel="stylesheet" media="screen">
编辑:我正在使用servlet 2.5,因为到目前为止,我无法将我的项目从JBoss 5升级到更高版本。JBoss5 不支持 servlet 3,这重要吗?
@Configuration
@ComponentScan("com.mgage.mvoice")
public class MyAppWebConfig extends WebMvcConfigurerAdapter {
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// I tried these many combinations separately.
ResourceHandlerRegistration resourceRegistration = registry
.addResourceHandler("resources/**");
resourceRegistration.addResourceLocations("/resources/**");
registry.addResourceHandler("/css/**").addResourceLocations("/css/**");
registry.addResourceHandler("/img/**").addResourceLocations("/img/**");
registry.addResourceHandler("/js/**").addResourceLocations("/js/**");
registry.addResourceHandler("/resources/**")
.addResourceLocations("classpath:/resources/");
// do the classpath works with the directory under webapp?
}
}