1

次のフォルダー構造を持つサンプル 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>
4

2 に答える 2

0

Spring 3.0.4.RELEASE 以降では、使用できます

<mvc:resources mapping="/resources/**" location="/public-resources/"/>

http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resourcesに見られるように

また、ページを に入れることは避けてくださいWEB-INFhtml/css/js階層の高いフォルダーをWeb アプリ フォルダーの下に配置します。通常、WEB-INF構成 xml ファイルのみが存在する必要があります。

于 2015-12-08T04:04:03.747 に答える