在spring 4.2后,提供了跨域注解@CrossOrigin

https://spring.io/guides/gs/rest-service-cors/

Enabling CORS

Controller method CORS configuration

So that the RESTful web service will include CORS access control headers in its response, you just have to add a @CrossOrigin annotation to the handler method:

src/main/java/hello/GreetingController.java

用例:

  @CrossOrigin(origins = "http://localhost:9000")
@GetMapping("/greeting")
public Greeting greeting(@RequestParam(required=false, defaultValue="World") String name) {
System.out.println("==== in greeting ====");
return new Greeting(counter.incrementAndGet(), String.format(template, name));
}

This @CrossOrigin annotation enables cross-origin requests only for this specific method. By default, its allows all origins, all headers, the HTTP methods specified in the @RequestMapping annotation and a maxAge of 30 minutes is used. You can customize this behavior by specifying the value of one of the annotation attributes: origins, methods, allowedHeaders, exposedHeaders, allowCredentials or maxAge. In this example, we only allow http://localhost:9000 to send cross-origin requests.

@CrossOrigin注解是被注解的方法具备接受跨域请求的功能。默认情况下,它使方法具备接受所有域,所有请求消息头的请求。。。。这个例子中,我们仅接受

http://localhost:9000发送来的跨域请求。

最新文章

  1. winform 进程,线程
  2. MSMQ 学习(1)
  3. tkprof 解释
  4. Android 迷之Version管理
  5. android:showAsAction="never"是做什么用的?
  6. 基于visual Studio2013解决面试题之1307二分查找
  7. Python 最大公约数的欧几里得算法及Stein算法
  8. Python的字典dictionary
  9. EF性能检测工具MiniProfilerEF6的使用
  10. Singer 学习二 使用Singer进行gitlab 2 postgres 数据转换
  11. mysql数据导入导出与数据表优化
  12. 使用javascript来访问本地文件夹
  13. Git简单配置ssh秘钥
  14. 雅礼集训DAY 6 T1 xmasdag
  15. Node.js小白开路(一)-- fs篇
  16. DropDownList绑定及修改
  17. JAVA 成员访问权限修饰符
  18. type=file文件上传H5新特性
  19. SpringBoot学习笔记(8):事物处理
  20. v$sql、v$sqlarea、v$sqltext、v$sql_plan

热门文章

  1. Shell 脚本实现TCP/UDP协议通讯
  2. 浅谈redux 中间件的原理
  3. (转)Oracle中判断某字段不为空及为空的SQL语句
  4. ZJOI2006书架
  5. letsencrypt的证书转换上传到360网站防护方法
  6. JMeter 分布式测试部署
  7. 在什么情况下Java比C++快?
  8. quote(),unquote(),urlencode()编码解码
  9. Python垃圾回收机制:gc模块(zz)
  10. python如何通过pymongo连接到mongodb?