SpringBoot project using Cors solve cross-domain problems

package com.chitic.supplywater.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Bean
    public CorsFilter corsFilter() {
        finalUrlBasedCorsConfigurationSource = UrlBasedCorsConfigurationSource new new UrlBasedCorsConfigurationSource ();
         Final CorsConfiguration corsConfiguration = new new CorsConfiguration (); 
        corsConfiguration.setAllowCredentials ( to true );
         / * allow access to the client domain name * / 
        corsConfiguration.addAllowedOrigin ( "*" );
         / * allow access to the server the client request header * / 
        corsConfiguration.addAllowedHeader ( "*" );
         / * name of the method to allow access, GET POST, etc. * / 
        corsConfiguration.addAllowedMethod ( "*" );
        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsFilter(urlBasedCorsConfigurationSource);
    }

}

 

Guess you like

Origin www.cnblogs.com/gaomanito/p/11390102.html