我是靠谱客的博主 害羞手链,这篇文章主要介绍【前端】使用vue-admin-template封装的Axios时跨域问题使用@CrossOrigin注解时,再用@RequestMapping会出现拦截失效,现在分享给大家,希望可以做个参考。

使用@CrossOrigin注解时,再用@RequestMapping会出现拦截失效

解决方法1:

如果是get请求那就用@GetMapping即可

解决方法2:

配置一个跨域配置类


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 解决跨域问题
 */
@Configuration
public class CORSConfigurer implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}

最后

以上就是害羞手链最近收集整理的关于【前端】使用vue-admin-template封装的Axios时跨域问题使用@CrossOrigin注解时,再用@RequestMapping会出现拦截失效的全部内容,更多相关【前端】使用vue-admin-template封装内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部