Interceptor Setting the response header this way the principle is to use interceptors before the method executes, we increase the requested response header to support cross-domain requests. Such a programme is feasible, and most of it is based on this approach. I was also planning to use this approach until I found out that the spring framework has supported CORS and has adopted the Spring Framework's built-in approach, but the same principle is true.
Direct configuration:
<!-- API 接口跨域配置 --><mvc:cors> <mvc:mapping path="/api/**" allowed-origins="*" allowed-methods="POST, GET, OPTIONS, DELETE, PUT" allowed-headers="Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" allow-credentials="true" /></mvc:cors>
Of course you can also use annotations on the controller @CrossOrigin . Similar to this:
Here, the support for CORS cross-domain requests is complete, and it is important to note that your Spring MVC version must be 4.2 and above .
Java-spring MVC for cross-domain resource CORS requests