首页 > 其他分享 >springboot允许跨域访问

springboot允许跨域访问

时间:2023-01-20 16:12:10浏览次数:39  
标签:springboot springframework 访问 org import config annotation 跨域

前后端开发学习中,vue里面需要跨域访问后台数据

可在springboot后台里面添加个配置类即可:

package com.springboottest.config;

import org.springframework.beans.factory.annotation.Configurable;
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 CrossConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET","HEAD","POST","PUT","DELETE","OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}

 

转自:https://www.cnblogs.com/bingyangzhang/p/12684818.html

扩展阅读:https://www.cnblogs.com/antLaddie/p/14751540.html

标签:springboot,springframework,访问,org,import,config,annotation,跨域
From: https://www.cnblogs.com/xuxiaobo/p/17062835.html

相关文章

  • springboot统一处理异常
    增加业务异常处理类:packagecom.example.demo.config;importlombok.Data;@DatapublicclassBizExceptionextendsRuntimeException{protectedIntegererr......
  • Mysql8开启root远程并设置访问密码
    和旧版本设置,有点不一样mysql-urootmysql>usemysql;#查看user表信息,注意密码字段已改为autentication_stringmysql>selectuser,host,authentication_string......
  • 42-Springboot整合HignLevelClient----构建复杂检索
    @Test voidsearchTest()throwsIOException{ SearchRequestsearchRequest=newSearchRequest(); //1、指定索引 searchRequest.indices("bank"); //2.1、......
  • 基于springboot的景区旅游信息管理系统(源代码+数据库)
    基于springboot的景区旅游信息管理系统(源代码+数据库)一、系统介绍本项目分为管理员与普通用户两种角色用户登录前台功能:旅游路线、旅游景点、旅游酒店、旅游车票、......
  • springboot整合minio
    代码参考GitHub地址安装minio1、进入官网:https://min.io/我目前安装的是版本是:在cmd窗口中,命令行进行minio.exe所在的文件夹,输入如下命令server后面的地址是你......
  • 41-Springboot整合HignLevelClient----给es中保存数据
    1、导入依赖 <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>elasticsearch-rest-high-level-client</artifactId> <version>7.4.2</v......
  • SpringBoot2(一)SpringBoot入门程序
    SpringBoot2(一)SpringBoot入门程序在整合SSM框架时,需要大量的配置文件,SpringBoot可以简化这些配置,提高开发效率。并且Spring内置了Tomcat、Jetty、Undertow容器。搭建Spri......
  • 61、全文检索--Springboot整合HignLevelClient
    注意:它默认帮我们导入的elasticsearch版本不是我们使用的7.4.2,因为我们的Springboot项目一致维护了elasticsearch的版本通过以下方式在我们的项目中自己指定版本......
  • 230119_50_SpringBoot入门
    多环境配置文件指定方式一:properites文件文件名可以是application-{profile}.properties/yml,用来指定多个环境版本:server.port=8081//testserver.port=80......
  • springboot上传下载文件原来这么丝滑
    我使用了hutool的 FileUtil,IdUtil,所以需要引入hutool:<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactI......