The problem occurs because
path = testDemo-server.servlet.context
spring.mvc.static-path-pattern = / static / **
After defining the project name and path discovery static resources, templates referenced in html css, js of abnormal relative path
in the above directory in, index.html reference css href = "../ static / xxx " can not obtain the relative path by the
server.servlet.context-path = href testDemo front of = "../ static / xxx" is not defined in a write There is no problem
after setting the project name, use relative paths will be missing when the project name, in order to gain less static resources
solution
- 1) Use an absolute path
- 2) modify the path, the href = "../ static / xxx" changed href = "static / xxx"
- 3) Use spring thymeleaf of th: src or th: href link tag change the path attribute, such as
<link rel="stylesheet" th:href="@{/pace/themes/blue/pace-theme-flash.css}>
But three schemes, the compiler does not recognize the path that leads to code a silent, very hard to accept this, and the following two scenarios to resolve the compiler can not prompt questions
- Also use spring thymeleaf of th: src or th: href, and write when coupled with multi-src, href compiled for identification ( recommended )
<link rel="stylesheet" href="../static/pace/themes/blue/pace-theme-flash.css"th:href="@{/pace/themes/blue/pace-theme-flash.css}">
- Thymeleaf do not use or do not want every css, js are introduced to write a path , add head in HTML <Base href = "XXX /"> tag, so you will not lose ../ project name, but removed the XXX /
<base href="XXX/"> <link rel="stylesheet" href="../static/pace/themes/blue/pace-theme-flash.css">
ending...