package com.example.vueblog.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") //接受所有跨域请求路径
.allowedOrigins("*") //允许所有的请求来源通过
.allowedMethods("GET","POST","DELETE","PUT","OPTION") //允许请求的方法
.allowCredentials(false) //允许请求发送身份凭证
.maxAge(3600) //请求的最大缓存时间
.allowedHeaders("Authorization","*"); //允许所有的请求头
}
}
package com.example.vueblog.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") //接受所有跨域请求路径
.allowedOrigins("*") //允许所有的请求来源通过
.allowedMethods("GET","POST","DELETE","PUT","OPTION") //允许请求的方法
.allowCredentials(false) //允许请求发送身份凭证
.maxAge(3600) //请求的最大缓存时间
.allowedHeaders("Authorization","*"); //允许所有的请求头
}
}