Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle JSONP (Spring Framework 5.1 )

Tags:

spring

I have hard time dealing with JSONP while migrating to Spring 5.1 from Spring 4

Spring 4 provides AbstractJsonpResponseBodyAdvice class for jsonp

However, AbstractJsonpResponseBodyAdvice class is gone in Spring 5.

Is there any supplementary class in Spring 5.1???

like image 772
Leo Avatar asked Oct 29 '22 02:10

Leo


1 Answers

AbstractJsonpResponseBodyAdvice was deprecated starting from Spring 5.0.7 and 4.3.18 and in version 5.1 it is completely removed. There is no direct replacement in Spring 5.1 and instead of using of insecure JSON-P you should migrate on CORS (Cross-Origin Resource Sharing) which allows you to specify what kind of cross domain requests are authorized.

Read more about CORS in Spring documentation here: https://docs.spring.io/spring/docs/5.0.x/spring-framework-reference/web.html#mvc-cors

And there is also lot of question regarding CORS on SO - for example: How to configure CORS in a Spring Boot + Spring Security application?


And of course there is always a dirty option where you can disembowel AbstractJsonpResponseBodyAdvice class and all its dependencies into separate jar and use it also with new versions of Spring but I think it is better to start with CORS ;-)

like image 98
cgrim Avatar answered Nov 01 '22 13:11

cgrim