package org.linlinjava.litemall.core.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; @Configuration
public class CorsConfig {
// 当前跨域请求最大有效时长。这里默认30天
private long maxAge = 30 * 24 * 60 * 60; private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头
corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法
corsConfiguration.setMaxAge(maxAge);
return corsConfiguration;
} @Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", buildConfig()); // 4 对接口配置跨域设置
return new CorsFilter(source);
}
}

CorsConfig的更多相关文章

  1. @EnableWebMvc WebMvcConfigurer CorsConfig

    package me.zhengjie.core.config; import org.springframework.context.annotation.Configuration; import ...

  2. 开源的Owin 的身份验证支持 和跨域支持

    http://identitymodel.codeplex.com/ https://identityserver.github.io/ Windows Identity Foundation 6.1 ...

  3. vue + vue-resource 跨域访问

    使用vue + vue-resource进行数据提交,后台使用RESTful API的方式存取数据,搞了一天,终于把后台搞好了.进行联合调试时,数据不能提交,报403错误: XMLHttpReques ...

  4. dog-fooding-our-api-authentication

    Dog-fooding our API - Authentication http://blog.mirajavora.com/authenticate-web-api-using-access-to ...

  5. jsonp与cors跨域的一些理解(转)

    CORS其实出现时间不短了,它在维基百科上的定义是:跨域资源共享(CORS )是一种网络浏览器的技术规范,它为Web服务器定义了一种方式,允许网页从不同的域访问其资源.而这种访问是被同源策略所禁止的. ...

  6. spring boot / cloud (六) 开启CORS跨域访问

    spring boot / cloud (六) 开启CORS跨域访问 前言 什么是CORS? Cross-origin resource sharing(跨域资源共享),是一个W3C标准,它允许你向一 ...

  7. ajax解决跨域问题

    1.在介绍之前先介绍几个概念 json: { date: "Sun Dec 24 21:44:42 CST 2017", temperature: "21", ...

  8. springboot解决跨域问题(Cors)

    1.对于前后端分离的项目来说,如果前端项目与后端项目部署在两个不同的域下,那么势必会引起跨域问题的出现. 针对跨域问题,我们可能第一个想到的解决方案就是jsonp,并且以前处理跨域问题我基本也是这么处 ...

  9. springMVC源码分析--AbstractHandlerMethodMapping注册url和HandlerMethod对应关系(十一)

    在上一篇博客springMVC源码分析--AbstractHandlerMethodMapping获取url和HandlerMethod对应关系(十)中我们简单地介绍了获取url和HandlerMet ...

随机推荐

  1. springBoot中的邮件发送

    1. 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  2. org.springframework.dao.CannotAcquireLockException异常分析

    错误信息如下: 2017-09-27 16:27:16.153 - [com.ldyun.base.service.impl.BaseRetailOrderServiceImpl] - 新增零售商品订 ...

  3. 委托、Action、Func使用

    参考 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syste ...

  4. 指针数组的初始化和遍历,并且通过for循环方式、函数传参方式进行指针数组的遍历

    /************************************************************************* > File Name: message.c ...

  5. git push报错! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://gitee.com/XXX.git

    git pull origin master --allow-unrelated-histories  //把远程仓库和本地同步,消除差异 git add . git commit -m"X ...

  6. Android 消息推送流程机制

    1.引言 所谓的消息推送就是从服务器端向移动终端发送连接,传输一定的信息.比如一些新闻客户端,每隔一段时间收到一条或者多条通知,这就是从服务器端传来的推送消息:还比如常用的一些IM软件如微信.GTal ...

  7. share团队冲刺7

    团队冲刺第七天 昨天:加入activity的内容,和队友的代码进行整合实现部分按钮功能 今天:继续完善代码,完善其他页面的功能,对主页和发表页面进行开发 问题:无

  8. JAVA中常用的异常处理情况

    1.java.lang.nullpointerexception程序遇上空指针 这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用了未经初始化的对象或者 ...

  9. 吴裕雄--天生自然 JAVA开发学习:方法

    /** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) re ...

  10. UML-如何使用层进行设计?

    1.将代码组织映射为层和UML包 com.mycompany |_nextgen |_ui |_domain |_service |_util org.apache.log4j  2.使用对象设计应用 ...