|
|
@ -2,8 +2,10 @@ package com.wh.config; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
|
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|
|
|
|
|
|
|
@Configuration |
|
|
|
public class WebMvcConfig implements WebMvcConfigurer { |
|
|
|
@Value("${yuan.file.root.path}") |
|
|
@ -16,4 +18,19 @@ public class WebMvcConfig implements WebMvcConfigurer { |
|
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) { |
|
|
|
registry.addResourceHandler("/archive/**").addResourceLocations("file:" + fileRootPath); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void addCorsMappings(CorsRegistry registry){ |
|
|
|
//设置允许跨域的路径
|
|
|
|
registry.addMapping ("/**") |
|
|
|
//设置允许跨域请求的域名
|
|
|
|
.allowedOrigins("*") |
|
|
|
//是否允许证书
|
|
|
|
.allowCredentials (true) |
|
|
|
//设置允许的方法
|
|
|
|
.allowedMethods ("GET","POST") |
|
|
|
//设置允许的header属性
|
|
|
|
.allowedHeaders ("*") |
|
|
|
//允许跨域时间
|
|
|
|
.maxAge (3600); |
|
|
|
} |
|
|
|
} |
|
|
|