java - Thymeleaf 错误加载静态文件

标签 java spring spring-mvc thymeleaf

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

enter image description here

在index.html中导入:

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

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

最精彩的部分是: enter image description here 检查网站时 - styles.css 作为 index.html 加载到 templates 文件夹中。

做什么?

最佳答案

在 Spring Security 4.x 中 - Spring Security 中的资源为 permitAll

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

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/css/**", "/js/**").permitAll()
}

关于java - Thymeleaf 错误加载静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54716579/

相关文章:

java - Spring 4 和 thymeleaf 表单验证

java - 如何克隆java TreeModel?

java - 为什么在java中同时运行和开始调用

java - JSch:从跳转服务器登录到目标服务器。跳转服务器要求输入 key 的密码,该 key 接受空字符串

java - JPA @ManyToOne 不存在 mappedBy 属性

java - Spring安全和Multipart

java - Spring Boot 2.0.4 + OAuth2 + JWT - 无法获取访问 token ,返回 405 或只是映射到 localhost :8080/

java - 命令行中的 Spring 属性

spring - GCM XMPP - 启动 Web 应用程序服务器时出错

java - Spring创建bean时出错