1、在项目启动入口类实现 WebMvcConfigurer 接口:

  

@SpringBootApplication
public class Application implements WebMvcConfigurer { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
} }

2、重写 addCorsMappings 方法:

@Override
public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**")
.allowCredentials(true)
.allowedHeaders("*")
.allowedOrigins("*")
.allowedMethods("*");
}

3、在controller 类上添加注解

@CrossOrigin

如图:

												

spring boot项目配置跨域的更多相关文章

  1. spring boot之配置跨域

    在启动类中配置 @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override p ...

  2. 009-Spring Boot全局配置跨域请求支持

    1.Spring Boot 2.0以前全局配置跨域主要是继承WebMvcConfigurerAdapter @Configuration public class CorsConfig extends ...

  3. spring boot:解决cors跨域问题的两种方法(spring boot 2.3.2)

    一,什么是CORS? 1,CORS(跨域资源共享)(CORS,Cross-origin resource sharing), 它是一个 W3C 标准中浏览器技术的规范, 它允许浏览器向非同一个域的服务 ...

  4. Vue-cli 创建的项目配置跨域请求(通过反向代理)---配置多个代理--axios请求

    问题描述: 使用 Vue-cli 创建的项目,开发地址是 localhost:8080,需要访问 localhost:9000 或https://m.maoyan.com或http://image.b ...

  5. Java Spring boot 2.0 跨域问题

    跨域 一个资源会发起一个跨域HTTP请求(Cross-site HTTP request), 当它请求的一个资源是从一个与它本身提供的第一个资源的不同的域名时 . 比如说,域名A(http://dom ...

  6. Spring Boot项目配置RabbitMQ集群

    //具体参看了配置的源码 org.springframework.boot.autoconfigure.amqp.RabbitProperties //RabbitMQ单机 spring:   rab ...

  7. Spring Boot 项目配置的使用方法

    第一种写法resources目录下的application.properties文件 第二种写法resources目录下的application.yml文件 在项目中获取配置项: 分组配置:  (配置 ...

  8. spring boot项目配置RestTemplate超时时长

    配置类: @Configuration public class FeignConfiguration { @Bean(name="remoteRestTemplate") pub ...

  9. spring boot 项目配置字符编码

随机推荐

  1. centos环境下使用CPAN安装perl模块

    首先安装CPAN yum install perl-CPAN 进入cpan环境 perl -MCPAN -e shell 安装模块(以Tk为例) cpan>install Tk 退出 cpan& ...

  2. sed常用操作命令

    sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据进行替换.删除.新增.选取等特定工作. 命令格式: sed [OPTION]... {script-only-i ...

  3. poj 1039

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdlib&g ...

  4. 高性能mysql的事物隔离级别

    数据库事务的隔离级别有4种,由低到高分别为Read uncommitted .Read committed .Repeatable read .Serializable .而且,在事务的并发操作中可能 ...

  5. windows下配置下burpsuite的小方法。

    1.下载破解版burpsuite和正版burpsuite. 2.安装正版burpsuite(免费版) 3.打开安装路径 4.把破解版的burp拷贝到安装路径下 5.该路径下应该有个burpsuite_ ...

  6. robotframework之去除空格、去掉前面的0、增加空格换行符的方法,两个字符之间的拼接

    1.去除空格 A)若需要去除两个拼接字符之间的空格,可以使用robotframework中的关键词Catenate,需要注意的是SEPARATOR=一定需要大写 B)若在一个字符串中存在空格,且需要去 ...

  7. js 实现拖拽排序

    <!DOCTYPE> <html lang="zh-cn"> <head> <meta http-equiv="Content- ...

  8. C++ 凸包生成算法

    由于我的极差记忆力,我打算把这个破玩意先记下来.因为以后会有改动(Delaunay三角网生成算法),我不想把一个好的东西改坏了... 好吧-- 凸包生成算法,: 1.先在指定的宽(width)高(he ...

  9. centos7镜像文件

    1.打开网址https://www.centos.org/download/2.点击Minimall ISO 按钮  3.选择aliyun地址 4.centos版本介绍 在CentOS官方网站上,Ce ...

  10. Boot Hill 布特山

    发售年份 1977 平台 街机 开发商 Midway 类型 射击 https://www.youtube.com/watch?v=yFVZhSCjo6w