我的Maven Spring项目目录结构如下所示。我正在使用基于Spring-4注释的配置。我像下面这样配置资源。我尝试了许多在Stackoverflow和其他网站上建议的方法,但jsp文件无法加载资源,所有静态内容请求都返回404错误。我在jsp中尝试了这些事情,
Spring 4 loading static resources
http://imwill.com/spring-mvc-4-add-static-resources-by-annotation/#.U5GZlXKs9i4
<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">
编辑:目前我无法将我的项目从JBoss 5升级到更高版本,因此我正在使用servlet 2.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?
}
}