从 Spring 4 迁移到 Spring 5.1 时,我很难处理 JSONP
Spring 4 为 jsonp 提供 AbstractJsonpResponseBodyAdvice 类
但是, AbstractJsonpResponseBodyAdvice 类在 Spring 5 中消失了。
Spring 5.1 有没有补课???
AbstractJsonpResponseBodyAdvice从 Spring 5.0.7 和 4.3.18 开始已弃用,在版本 5.1 中它被完全删除。Spring 5.1 中没有直接替代方案,您应该迁移到CORS(跨源资源共享),而不是使用不安全的 JSON-P,它允许您指定授权哪种跨域请求。
在 Spring 文档中阅读有关 CORS 的更多信息: https: //docs.spring.io/spring/docs/5.0.x/spring-framework-reference/web.html#mvc-cors
关于 SO 上的 CORS 也存在很多问题 - 例如:如何在 Spring Boot + Spring Security 应用程序中配置 CORS?
当然,总有一个肮脏的选择,您可以将AbstractJsonpResponseBodyAdvice类及其所有依赖项分解到单独的 jar 中,并将其与新版本的 Spring 一起使用,但我认为最好从 CORS 开始;-)
| 归档时间: |
|
| 查看次数: |
2573 次 |
| 最近记录: |