前后端分离两套服务 前端请求跨域问题不让访问和问题解决
发布时间
阅读量:
阅读量
系统架构采用前后端分离模式,前端与后端分别运行于独立的服务进程之中,二者所使用的端口号存在差异,IP地址也可能不一致。这种情况下,浏览器会将请求判定为跨域操作,从而阻止访问。为解决此问题,需在后台服务中添加相应配置以支持跨域访问。以下为Spring Boot框架中实现统一跨域配置的代码示例。
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/** * @desc mvc配置
* @date 2021-5-14
* @author Huan
全部评论 (0)
还没有任何评论哟~
