次のフォルダー構造を持つサンプル 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
}
サーブレットのマッピングは次のとおりです
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>