spring boot 跨域解决

阅读更多

寻常的跨域解决方式有

 

1、 src > javascript中

2、 jsonp

3、 cors后台框架修改xml

 


    crossDomain
    CORS
    com.thetransactioncompany.cors.CORSFilter
    
        cors.allowOrigin
        *
    
    
        cors.supportedMethods
        GET, POST, HEAD, PUT, DELETE
    
    
        cors.supportedHeaders
        Accept, Origin, X-Requested-With, Content-Type, Last-Modified,x_requested_with
    
    
        cors.exposedHeaders
        Set-Cookie
    
    
        cors.supportsCredentials
        true
    


    CORS
    /*
4 springboot集成Cors,在appliction.java中添加这段
	@Bean
	public WebMvcConfigurer corsConfigurer() {
		return new WebMvcConfigurerAdapter() {
			@Override
			public void addCorsMappings(CorsRegistry registry) {
				registry.addMapping("/**")
						.allowedOrigins("*")
						.allowedMethods("PUT", "DELETE","GET","POST")
						.allowedHeaders("*")
						.exposedHeaders("access-control-allow-headers",
								"access-control-allow-methods",
								"access-control-allow-origin",
								"access-control-max-age",
								"X-Frame-Options")
						.allowCredentials(false).maxAge(3600);
			}
		};

	}
 
 

你可能感兴趣的:(springboot,跨域,Cors)