为了账号安全,请及时绑定邮箱和手机立即绑定

Thymeleaf 错误地加载静态文件

Thymeleaf 错误地加载静态文件

哆啦的时光机 2022-06-23 16:19:45
因此,我正确加载了静态 css 文件,然后出于某种原因,不知道为什么,它们正确地停止了加载。这是我的项目结构:在 index.html 中导入:<head>  <link rel="stylesheet" th:href="@{/css/styles.css}"/></head>我什至尝试设置spring.resources.static-locations=classpath:/static/都application.properties无济于事。最好的部分:检查网站时 -styles.css加载为index.html文件templates夹。做什么?
查看完整描述

2 回答

?
茅侃侃

TA贡献1842条经验 获得超22个赞

在 spring security 4.x 中 - 资源permitAll在 spring security 中。


在 spring security 5.x - 你应该手动配置它。


@Override

protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests().antMatchers("/css/**", "/js/**").permitAll()

}


查看完整回答
反对 回复 2022-06-23
?
繁花如伊

TA贡献2012条经验 获得超12个赞

请尝试检查以下几点:

1. ResourceHandler 有 css 位置


class WebConfig implements WebMvcConfigurer {

  @Override

  public void addResourceHandlers(ResourceHandlerRegistry registry) {

    registry.addResourceHandler("/css/**")

      .addResourceLocations("classpath:/static/css/");

  }


  ...

}

2.在spring-security规则中排除*.css


class SecurityConfig extends WebSecurityConfigurerAdapter {


  @Override

  public void configure(WebSecurity web) throws Exception {

    web.ignoring().antMatchers(

      "/css/\**",

      "/js/\**",

      "/img/\**",

      ...

    );

  }


  ...

}


查看完整回答
反对 回复 2022-06-23
  • 2 回答
  • 0 关注
  • 172 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号