Spring boot 解决跨域问题

import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author chenduan
 * 解决跨域问题
 * Controller继承此类
 */
public class Cors extends WebMvcConfigurerAdapter {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").
                allowedOrigins("*").
                allowedMethods("GET", "POST", "PUT", "OPTIONS", "DELETE", "PATCH")
                .allowCredentials(true).maxAge(3600);

    }
}

 

posted @ 2019-08-08 17:10  喜葵  阅读(177)  评论(0编辑  收藏  举报