zuul(springboot)設置靜態資源代理和默認首頁代碼一例

直接上代碼:html

public class StaticResourcesConfig extends WebMvcConfigurerAdapter {
private static final Log log = LogFactory.getLog(StaticResourcesConfig.class);

    @Override
    /**
     * 設置默認首頁
     */
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("redirect:/index.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/path/**").addResourceLocations("file:/html/);

    }
}

第二個方法能夠添加靜態資源映射,linux

在linux下,若是經過http://[server ip]/path/index.html進行訪問,則能夠訪問到磁盤路徑爲  /html/index.html 的文件windows

在windows下則能夠將代碼中的 /html/ 換成 [盤符]:/html/ D:/html/ide

 

提醒一下:spa

若是用的是容器,不要忘記目錄映射code

相關文章
相關標籤/搜索