【问题标题】:Spring Boot application with WebSecurity doesn't see css带有 WebSecurity 的 Spring Boot 应用程序看不到 css
【发布时间】:2020-08-26 05:09:43
【问题描述】:

我有一个扩展 WebSecurityConfigurerAdapter 的 webSecConfig 类。我将它的方法粘贴到我尝试使用 .antMatchers 允许访问的地方。 我的文件夹结构: ... -资源 --static(这里我有 html/css 的图片) --模板 ---登录.html ---设计.css 我曾尝试添加基于某些 cmets 的“公共”文件夹,但到目前为止似乎没有任何效果。谁能帮我解决这个问题?

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .formLogin()
            .loginPage("/login").permitAll()
            .loginProcessingUrl("/login")
            .defaultSuccessUrl("/messages", true)
            .and()
            .logout()
            .logoutSuccessUrl("/login")
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
            .and()
            .authorizeRequests()
            .antMatchers("/login", "resources/**").permitAll()
            .anyRequest().authenticated();
}

【问题讨论】:

    标签: css spring spring-boot staticresource websecurity


    【解决方案1】:

    我设法解决了!我将我的 css 放在资源/静态内的 css 文件夹中。我在 antMatchers 部分使用了“/css/**”。对 css 的 href 也应该是:href="/css/design.css",我的 IDE 已将其重构为 href="../static/css/design.css" 这是错误的,所以请注意这一点!我希望它会帮助别人!

    【讨论】:

      猜你喜欢
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 2018-12-05
      • 2015-03-28
      相关资源
      最近更新 更多