• 关于spring security中设置header无效问题解决方式.


    1.查看spring security,发现会自动创建多个对象。此时需要通过排序来进行,将自己设置的配置文件提前初始化来满足

    2.原因找到了。自己配置了多个config。所以造成创建了多个filter。这里一定要注意哦~~~

    @EnableWebSecurity
    @Order(1) //排序来处理这样的问题。但是没有治本,需要查看为什么要初始化多个对象...
    public class SecurityConfig extends WebSecurityConfiguerAdapter {
    
        @Override
        protected void configure(HttpSecurity http) throws Exception {
    //这里会新建一个对象。 http.headers().frameOptions().sameOrigin(); // 同源跨域,默认DENY http.csrf().disable() .authorizeRequests() .anyRequest().permitAll() .and().logout().permitAll(); http.cors().configurationSource(corsConfigurationSource()); } //配置跨域访问资源 private CorsConfigurationSource corsConfigurationSource() { CorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("*"); // 同源配置,*表示任何请求都视为同源,若需指定ip和端口可以改为如“localhost:8080”,多个以“,”分隔; corsConfiguration.addAllowedHeader("*");// header,允许哪些header corsConfiguration.addAllowedMethod("*"); // 允许的请求方法,PSOT、GET等 ((UrlBasedCorsConfigurationSource) source).registerCorsConfiguration("/**", corsConfiguration); // 配置允许跨域访问的url return source; } }

      

  • 相关阅读:
    mybatis使用Example进行条件查询
    博客园页面DIY
    内网穿透
    使用ResponseEntity进行返回json数据
    spring中的ResponseEntity理解
    springboot整合mybatis通用Mapper
    解决pip安装过慢的问题
    【记录】linux 命令拷贝文件到远程服务器,linux下载文件到本地
    【记录】ELK之logstash同步mysql数据到Elasticsearch ,配置文件详解
    【记录】logstash 命令解释
  • 原文地址:https://www.cnblogs.com/zf-crazy/p/14314698.html
Copyright © 2020-2023  润新知