【问题标题】:Spring boot cannot load css from user folderSpring Boot 无法从用户文件夹加载 css
【发布时间】:2017-04-25 20:03:25
【问题描述】:

我目前正在开发 Spring Boot 和 thymeleaf 的 Web 应用程序。 我设法通过从文件夹“resources/static”中调用资源 css 和 js 来设置 web-front。

但是,对于“resources/template/app/index.html”文件夹中的用户空间,我不能在“resources/static/app_css/bootstrap.css”中调用我的css。

这是我的文件树:

我的 index.html 来自 resources/templates/app/

    <!DOCTYPE html>
    <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
    <head th:include="app_fragments/header :: header">
        <p>Header</p>
    </head>
    <body>
   <!-- Indicates a successful or positive action -->
<button type="button" class="btn btn-success">Success</button>
    </body>
    </html>

resources/templates/app_fragments/ 我的头文件片段:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:fragment="header">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
    <meta name="description" content=""/>
    <meta name="author" content=""/>
    <link rel="shortcut icon" th:href="@{../resources/app_fonts/app_images/favicon.png}" href="../resources/static/app_fonts/app_images/favicon.png"  type="image/png"/>
    <title>Toto</title>
<!-- Plugins CSS -->
<link rel="stylesheet" type="text/css" media="all" th:href="@{../resources/static/app_css/bootstrap.min.css}" href="../resources/static/app_css/bootstrap.min.css" />
</head>
</html>

当我进入用户空间时,我无法从http://localhost:8081/app/index.html 加载我的引导文件

如何解决?

提前致谢。

【问题讨论】:

    标签: twitter-bootstrap spring-mvc spring-boot thymeleaf


    【解决方案1】:

    您应该阅读“如何使用 Spring Boot 提供静态内容”。

    我已经在这里回答了这个问题:

    Spring Boot CSS Showing up blank / not loading after trying everything

    长话短说,首先将您的静态内容移动到正确的文件夹中,这是来自 spring 文档的引用:

    默认情况下,Spring Boot 将提供目录中的静态内容 在中称为 /static(或 /public 或 /resources 或 /META-INF/resources) 类路径或 ServletContext 的根目录

    之后,您需要进行一些配置以破坏浏览器缓存。

    先尝试清理浏览器缓存,在谷歌浏览器中进入设置,然后清除浏览数据。

    其次,将这些行添加到您的 application.properties 文件中以破坏缓存:

    spring.resources.chain.strategy.content.enabled=true
    spring.resources.chain.strategy.content.paths=/**
    

    或者添加这个:

    spring.resources.chain.strategy.fixed.enabled=true
    spring.resources.chain.strategy.fixed.paths=/**
    spring.resources.chain.strategy.fixed.version=v12
    

    【讨论】:

      猜你喜欢
      • 2019-02-26
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多