package com.yssh.config;
|
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
/**
|
* @author wMeng
|
* @ClassName CorsConfig
|
* @Description 跨域配置
|
* @date 2022/10/31 16:42
|
* @Version 1.0
|
*/
|
@Configuration
|
public class CorsConfig implements WebMvcConfigurer {
|
|
@Override
|
public void addCorsMappings(CorsRegistry registry) {
|
registry.addMapping("/**")
|
.allowedOrigins("*")
|
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
|
.maxAge(3600)
|
.allowCredentials(true);
|
}
|
|
/**
|
* 20230213修改跨域配置
|
* @author xing
|
* */
|
/*@Bean
|
public CorsFilter corsFilter() {
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
corsConfiguration.addAllowedOrigin("*");
|
corsConfiguration.addAllowedHeader("*");
|
corsConfiguration.addAllowedMethod("*");
|
//corsConfiguration.addAllowedMethod(HttpMethod.GET);
|
//corsConfiguration.addAllowedMethod(HttpMethod.POST);
|
corsConfiguration.setAllowCredentials(true);
|
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
return new CorsFilter(urlBasedCorsConfigurationSource);
|
}*/
|
}
|