SpringBoot解决浏览器跨域问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012012240/article/details/81046003
package 类路径;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 解决浏览器跨域问题
 */
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {

   @Override
    public void addCorsMappings(CorsRegistry registry) {
      registry.addMapping("/**")
         .allowedOrigins("*")
         .allowedMethods("*")
         //.allowedMethods("PUT", "DELETE","POST","GET","OPTIONS")
         .allowedHeaders("*")
         //.exposedHeaders("header1", "header2")
         .allowCredentials(true).maxAge(3600);
   }
}

猜你喜欢

转载自blog.csdn.net/u012012240/article/details/81046003
今日推荐