spring boot项目配置跨域
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项目配置跨域的更多相关文章
- spring boot之配置跨域
在启动类中配置 @Bean public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurer() { @Override p ...
- 009-Spring Boot全局配置跨域请求支持
1.Spring Boot 2.0以前全局配置跨域主要是继承WebMvcConfigurerAdapter @Configuration public class CorsConfig extends ...
- spring boot:解决cors跨域问题的两种方法(spring boot 2.3.2)
一,什么是CORS? 1,CORS(跨域资源共享)(CORS,Cross-origin resource sharing), 它是一个 W3C 标准中浏览器技术的规范, 它允许浏览器向非同一个域的服务 ...
- Vue-cli 创建的项目配置跨域请求(通过反向代理)---配置多个代理--axios请求
问题描述: 使用 Vue-cli 创建的项目,开发地址是 localhost:8080,需要访问 localhost:9000 或https://m.maoyan.com或http://image.b ...
- Java Spring boot 2.0 跨域问题
跨域 一个资源会发起一个跨域HTTP请求(Cross-site HTTP request), 当它请求的一个资源是从一个与它本身提供的第一个资源的不同的域名时 . 比如说,域名A(http://dom ...
- Spring Boot项目配置RabbitMQ集群
//具体参看了配置的源码 org.springframework.boot.autoconfigure.amqp.RabbitProperties //RabbitMQ单机 spring: rab ...
- Spring Boot 项目配置的使用方法
第一种写法resources目录下的application.properties文件 第二种写法resources目录下的application.yml文件 在项目中获取配置项: 分组配置: (配置 ...
- spring boot项目配置RestTemplate超时时长
配置类: @Configuration public class FeignConfiguration { @Bean(name="remoteRestTemplate") pub ...
- spring boot 项目配置字符编码
随机推荐
- JavaScript调用上下文(第九天)
call与apply用法 使用哪个对象去调用相应的方法: var name="window"; var obj={ name:"obj" } function ...
- Python 找零问题
#coding = utf-8 def Change_Money(money): print('总金额:'+str(money)+'元') loop=True tmp=[] # 面值列表 单位:元 t ...
- 简单git使用命令
// 查看分支:git branch // 创建分支:git branch <name> // 切换分支:git checkout <name> // 创建+切换分支:git ...
- 通过junit写unit test
how to run test within junit & mvn: During team development , there are more than 1 person edit ...
- Developing avb
ai automake ai libtool ai pkg-config autogen ai libgstreamer1.0-0 ai libgstreamer1.0-dev ai chec ...
- Docker系列(二)镜像下载、操作容器、镜像导入导出等操作
一.镜像操作 列出镜像 $sudo docker images 从dockerhub检索image $docker search image_name 下载image $docker pull ima ...
- 关于mysql 的 autoCommit 参数
首先描述一下这个参数的作用. 这个参数 默认是开启的. 开启以后再命令敲的sql 会自动提交.如果关闭,就必须手动 commit. 查看 这个 自动提交状态. SELECT @@autocommit; ...
- tomcat catalina.out乱码
启动参数添加-Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8解决
- django 的后台管理
class bcb(models.Model): name = models.CharField(max_length=64,verbose_name='班次名称') verbose_name = ' ...
- 【转】redis实现的分布式锁
参考: 1. https://www.bbsmax.com/A/WpdKpM1zVQ/ 2.https://www.oschina.net/translate/redis-distlock