package com.qif.xdqdm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter; /**
* @author
* @date 2019年3月19日16:40:48
*/ @Configuration
public class CorsConfigFilter {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
//允许任何域名
corsConfiguration.addAllowedOrigin("*");
//允许任何头
corsConfiguration.addAllowedHeader("*");
//允许任何方法
corsConfiguration.addAllowedMethod("*");
return corsConfiguration;
} @Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//注册
source.registerCorsConfiguration("/**", buildConfig()); return new CorsFilter(source);
} }
package com.qif.xdqdm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; @Configuration
public class MyConfig extends WebMvcConfigurerAdapter { //所有的WebMvcConfigurerAdapter组件都会一起起作用
@Bean //将组件注册在容器 设置初始页面为index
public WebMvcConfigurerAdapter webMvcConfigurerAdapter() {
WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
}
};
return adapter;
} //解决跨域
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
} }

springboot跨域问题解决的更多相关文章

  1. django 前端请求跨域问题解决

    django 前端请求跨域问题解决 笔者之前在做django-restful-api开发的时候,在前端请求页面发送请求的时候直接出现301,域名重定向的问题,经过一番查阅资料,终于得到了非常完美的解决 ...

  2. Vue项目在开发环境跨域和生成环境部署跨域问题解决

    一.在dev环境下的跨域问题解决1.项目使用的是axios请求网络,将baseUrl修改为/api (这里是使用webpack提供的代理功能将/api代理成目标接口host) axios.defaul ...

  3. 前后端分离框架前端react,后端springboot跨域问题分析

    前后端分离框架前端react,后端springboot跨域问题分析 为啥跨域了 前端react的设置 springboot后端设置 为啥跨域了 由于前后端不在一个端口上,也是属于跨域问题的一种,所以必 ...

  4. FastAdmin 关于跨域问题解决

    FastAdmin 关于跨域问题解决 之前很久之前收集到社区的问题. https://forum.fastadmin.net/thread/277 今天又有人问到,无法打开,估计是网络问题. 以下为完 ...

  5. springmvc springboot 跨域问题(CORS)

    官方文档:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cors.html springmvc s ...

  6. vue跨域问题解决(生产环境)

    vue跨域问题解决(使用webpack打包的) 配置代理:(config下index.js文件) module.exports = { dev: { env: require('./dev.env') ...

  7. 两种解决springboot 跨域问题的方法示例

    两种解决springboot 跨域问题的方法示例,哪种方法看情况而定,自己选择.社会Boolean哥,人狠话不多,直接上代码. 第一种实现方式:       此种方式做全局配置,用起来更方便,但是无法 ...

  8. ajax请求ashx跨域问题解决办法

    ajax请求ashx跨域问题解决办法 https://blog.csdn.net/windowsliusheng/article/details/51583566 翻译windowsliusheng  ...

  9. Angular2发送HTTP请求SpringBoot后台跨域问题解决

    Angular通过http发送post请求至SpringBoot的Controller,由于同源策略的保护,遇到跨域问题: • 源(origin)就是协议(http).域名(localhost)和端口 ...

随机推荐

  1. C++与JAVA语言区别

            转载自:http://www.cnblogs.com/cnryb/archive/2011/01/04/2004141.html "作为一名C++程序员,我们早已掌握了面向对 ...

  2. tf.matmul() 和tf.multiply() 的区别

    1.tf.multiply()两个矩阵中对应元素各自相乘 格式: tf.multiply(x, y, name=None) 参数: x: 一个类型为:half, float32, float64, u ...

  3. Git部署项目

    前言 学习Git的目标是要学会如何部署项目.Git是一种版本控制系统,与之对应的还有CVS和SVN,其中CVS和SVN都是集中式的版本控制,而Git是一种分布式的,在现代项目开发中,大多使用Git来管 ...

  4. Dubbo执行流程?

    Dubbo执行流程? 0 start: 启动Spring容器时,自动启动Dubbo的Provider 1.register: Dubbo的Provider在启动后自动会去注册中心注册内容.注册的内容包 ...

  5. Centos6.5 安装 LAMP

    Centos 安装 LAMP 系统: Centos 6.5 Apache 2.4 + PHP 7.2 + Mysql 5.7 准备工作 centos 查看版本 查看 centos版本 How to C ...

  6. twentytwenty插件,图片对比轮播

    https://zurb.com/playground/twentytwenty 项目应用 http://decortrim.mml.digital/

  7. win10 快速访问存在 2345Downloads 删除解决方案

    有时候重装新系后统会发有很多自己不喜欢的捆绑程序,比如2345辣鸡浏览器 这个时候很多人会选择卸载,然后把文件夹位置删除 但是删除后会发现有一个地方一直还在那就是现快速访问的位置里面 这个位置由于卸载 ...

  8. NX二次开发-UFUN按类型遍历名字获取Tag函数UF_OBJ_cycle_by_name_and_type

    NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_obj.h> #include <u ...

  9. JS常见的报错类型

    解决错误前,首先要学会阅读报错信息 eg:Uncaught TypeError: ... is not a function Uncaught 表示没有被catch语句捕获到的错误 TypeError ...

  10. favicon.ico请求处理

    favicon.ico 图标用于收藏夹图标和浏览器标签上的显示,如果不设置,浏览器会请求网站根目录的这个图标,如果网站根目录也没有这图标会产生 404. 出于优化的考虑,要么就有这个图标,要么就禁止产 ...