Spring Security+Spring Boot 无法访问静态资源 401-跨域问题解决

  • 401告诉我没有权限,一开始我还以为时静态资源没有开放
package cn.hcnet2006.blog.hcnetwebsite.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

- 
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedHeaders("*")
                .allowedOrigins("*")
                .allowedMethods("*");


}}
发布了70 篇原创文章 · 获赞 29 · 访问量 6167

猜你喜欢

转载自blog.csdn.net/weixin_43404791/article/details/104773472