2016-12-29 12 views
0

私は静的コンテンツ(HTML、CSS、JavaScriptファイル)で次のフォルダを持っている:春ブーツMavenのWebアプリケーションフォルダとResourceHandler

/src/main/webapp/docs/ 

これは私のアプリケーションのプロパティです:

server.port: 8080 
server.contextPath: /admin-api 

ユーザーが次のURLにアクセスしたとき:http://localhost:8080/admin-api/docs私は彼に/src/main/webapp/docs/フォルダの静的コンテンツを表示します。

は、私は私のWebMvcConfigurerAdapterResourceHandlerを設定しようとしているが、それは動作しません:

@EnableWebMvc 
@Configuration 
public class WebMvcConfig extends WebMvcConfigurerAdapter { 

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     String[] staticResourceMappingPath = { "/docs/", "classpath:/docs/" }; 
     registry.addResourceHandler("/docs").addResourceLocations(staticResourceMappingPath); 
    } 

... 
} 

http://localhost:8080/admin-api/docsリターン404が見つかりません。

私は間違って何を正しく設定するのですか?

答えて

2

addResourceHandlersの方法は以下のようになります。あなたは、静的なページを持っている場合

@Override 
public void addResourceHandlers(ResourceHandlerRegistry registry) { 
    registry.addResourceHandler("/docs/**").addResourceLocations("/docs/"); 
} 

は今、あなたが使用してアクセスすることができDocsフォルダにindex.html言うhttp://localhost:8080/admin-api/docs/index.html