猿问

Thymeleaf 错误地加载静态文件

因此,我正确加载了静态 css 文件,然后出于某种原因,不知道为什么,它们正确地停止了加载。这是我的项目结构:

在 index.html 中导入:


<head>

  <link rel="stylesheet" th:href="@{/css/styles.css}"/>

</head>

我什至尝试设置spring.resources.static-locations=classpath:/static/都application.properties无济于事。


最好的部分:

http://img1.mukewang.com/62b42240000153b506600170.jpg

检查网站时 -styles.css加载为index.html文件templates夹。

做什么?


哆啦的时光机
浏览 173回答 2
2回答

茅侃侃

在 spring security 4.x 中 - 资源permitAll在 spring security 中。在 spring security 5.x - 你应该手动配置它。@Overrideprotected void configure(HttpSecurity http) throws Exception {&nbsp; &nbsp; http.authorizeRequests().antMatchers("/css/**", "/js/**").permitAll()}

繁花如伊

请尝试检查以下几点:1. ResourceHandler 有 css 位置class WebConfig implements WebMvcConfigurer {&nbsp; @Override&nbsp; public void addResourceHandlers(ResourceHandlerRegistry registry) {&nbsp; &nbsp; registry.addResourceHandler("/css/**")&nbsp; &nbsp; &nbsp; .addResourceLocations("classpath:/static/css/");&nbsp; }&nbsp; ...}2.在spring-security规则中排除*.cssclass SecurityConfig extends WebSecurityConfigurerAdapter {&nbsp; @Override&nbsp; public void configure(WebSecurity web) throws Exception {&nbsp; &nbsp; web.ignoring().antMatchers(&nbsp; &nbsp; &nbsp; "/css/\**",&nbsp; &nbsp; &nbsp; "/js/\**",&nbsp; &nbsp; &nbsp; "/img/\**",&nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; );&nbsp; }&nbsp; ...}
随时随地看视频慕课网APP

相关分类

Java
我要回答