1. 程式人生 > >spring boot 靜態資源映射

spring boot 靜態資源映射

mp4 hadoop ont reg system ssp test nds handler

package com.ehongcn.ccp.ss.dd.common.security;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class DdConfig extends WebMvcConfigurerAdapter {

@Value("${hadoop.static.resource.path}")
private String hadoopStaticResourcePath;

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// 將所有/static/** 訪問都映射到classpath:/static/ 目錄下
registry.addResourceHandler("/localStatic/**").addResourceLocations(
"file:D:/Java-Dev/workspace/maven.1524747092348/ccp-system-controlling/src/main/webapp/WEB-INF/classes/META-INF/resources/dist"
+ hadoopStaticResourcePath);

}

}

瀏覽器直接訪問或js請求 http://localhost:8080(端口號)/localStatic/test.mp4(文件名)

可直接訪問D:/...(絕對路徑)下的靜態資源。

spring boot 靜態資源映射