目录
- SpringBoot编程解决跨域Cores
- SpringBoot允许跨域
- 解决办法
- 总结
SpringBoot解决跨域Cores
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 CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOriginPatterns("*") .allowedHeaders("*") .allowedMethods("*") .allowCredentials(true) .maxAge(3600); } }
SpringBoot允许跨域
解决办法
@SpringBoothttp://www.devze.comApplication @MapperScan("com.humorchen.pastry_examination.mapper") public class PastryExaminationApplication implements WebMvcConfigurer { public static void main(String[] args) { SpringApplication.run(PastryExaminationApplication.class, args); } @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowCredentials(true) .allowedHeaders("*") .allowedOriginPatterns("*") http://www.devze.com .allowedMethods("*"); } }
新版本springbootphp跨域解决办法,把这个配置bean注入就可以了
@Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedHeaders("*") .allowedMethods("*") .allowedOrigins("*") .allowCredentials(true); } }; }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.cppcns.http://www.devze.comcom)。
精彩评论