templates.service.CorsConfig.ftl Maven / Gradle / Ivy
package ${packageName}.service.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
/**
* @author Co.
* @name CorsConfig
* @date 2023/3/27 11:16
*/
@Configuration
public class CorsConfig {
@Bean
CorsWebFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
//允许任何域名
config.addAllowedOrigin("*");
//允许任何头
config.addAllowedHeader("*");
//允许任何方法
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);
}
}