// 1.x 方式 ,继承抽象类:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.hsbc.gbm.hss.chinacustody.filemonitoring.common.PropertiesUtil;
@Configuration
public class VirturePathConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String vPath = "vpath";
if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
vPath = "file:" + vPath;
}
registry.addResourceHandler("/" + vPath + "/**").addResourceLocations(vPath+"/");
}
}
// 2.x 方式,实现接口类:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class VirturePathConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
String vPath = "vpath";
if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
vPath = "file:" + vPath;
}
registry.addResourceHandler("/" + vPath + "/**").addResourceLocations(vPath+"/");
}
}