ETJava Beta | Java    注册   登录
  • Spring & Springboot处理跨域问题

    发表于 2024-09-11 20:24:06     阅读(250)     博客类别:网络

    Spring或Springboot中解决跨域问题

     

    package com.et.conf;
    
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    /**
     * 处理跨域问题
     */
    @Configuration
    public class WebAppConfigurer implements WebMvcConfigurer {
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
                    .allowCredentials(true)
                    .allowedOrigins("*")
                    .maxAge(3600);
        }
    }
    

     

上一篇: MySQL创建库异常解决


下一篇:Spring加载bean