简体   繁体   English

使用Spring 3.x实现CORS

[英]CORS implementation with Spring 3.x

I want to know what are the possible solutions for allowing Cross Origin Resource Sharing between my Website and API Server. 我想知道在我的网站和API服务器之间允许跨源资源共享的可能解决方案是什么。 And what will be the best approach? 什么是最好的方法?

These are the possible solutions: 这些是可能的解决方案:

1) Implement as it is implemented in Spring 4.2 using CORS Filter (Link for JIRA of this Feature https://jira.spring.io/browse/SPR-9278 and the implementation is here https://bitbucket.org/thetransactioncompany/cors-filter/src/cba65d9a30e1db457df57d7689dee3244026a916/src/main/java/com/thetransactioncompany/cors/?at=master ) 1)使用CORS过滤器实现Spring 4.2中的实现(此功能的JIRA链接https://jira.spring.io/browse/SPR-9278 ,实现在这里https://bitbucket.org/thetransactioncompany/ cors-filter / src / cba65d9a30e1db457df57d7689dee3244026a916 / src / main / java / com / thetransactioncompany / cors /?at = master

2) By using Interceptor 2)使用拦截器

3) Simply write a filter that adds cross origin headers in all servlet responses 3)只需编写一个过滤器,在所有servlet响应中添加跨源头

4) Using JSONP as your data type in ajax request 4)在ajax请求中使用JSONP作为数据类型

I will prefer the first one. 我更喜欢第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM