All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.service.CorsConfig.ftl Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy