我创建了具有以下文件夹结构的示例 Spring MVC REST Maven 项目
ResourceHandlerRegistry 配置如下
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.raju.spring_app")
public class RootConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static_res/*").addResourceLocations("/WEB-INF/html/static_res/");
}
//Other methods
}
Servlet映射如下
public class HelloWorldInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected String[] getServletMappings() {
return new String[] { "/", "/static_res/*" };
}
//Other Methods
}
问题是每当我尝试访问资源 http://localhost:8080/spring4_rest_angular_demo/static/css/app.css
我收到 404 错误。我想保留此文件夹结构以在 index.jsp 文件中获取 css IntelliSense 建议。
<link href="static_res/css/app.css" rel="stylesheet"></link>