1. 程式人生 > >配置虛擬路徑,用於圖片展示等

配置虛擬路徑,用於圖片展示等

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {


@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
//swagger路徑
.addResourceLocations("classpath:/META-INF/resources/")
//虛擬化圖片/音樂路徑
.addResourceLocations("file:D:/eclipsework/xiaochengxu/imooc-videos-dev/");
}

}

因為用的是swagger2,之前沒有配置這個,需要單弄一個tomcat作為圖片伺服器地址。現在啟動好了之後,直接

localhost:xxxx/ 你的圖片相對於虛擬化的路徑xxx.jpg 就可以訪問了