내 프로젝트 트리는 다음과 같습니다Thymeleaf + Spring-Boot - 정적 리소스에 액세스 할 수없는 이유는 무엇입니까?
내가 지금 템플릿에 액세스 할 수 있지만 같은 CSS, 이미지, JS 등의 정적 리소스를로드 할 수 없습니다.
<link rel="stylesheet" th:href="@{/css/app.css}"/>
헤더 조각 나는 common.html
과 같이 다음과 같습니다 :
common.html
조각이
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head th:include="fragments/common :: commonFragment" lang="en"></head>
// page body
</html>
레이아웃에 대한 default.html
파일 :
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head th:include="fragments/common :: commonFragment" lang="en">
<meta charset="utf-8"/>
<meta name="robots" content="noindex, nofollow"/>
<title>Touch</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="content-dataType" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<link rel="shortcut icon" th:href="@{/static/images/favicon.ico}" type="image/x-icon" />
</head>
<body>
<div th:id="defaultFragment" th:fragment="defaultFragment" class="container">
<div id="header" th:replace="fragments/header :: headerFragment" />
<div layout:fragment="content" />
</div>
</body>
</html>
또한, 내 application.properties
파일에, 나는 이러한 항목이 있습니다
#SPRING RESOURCE HANDLING
spring.resources.static-locations=classpath:/resources/
#THYMELEAF
spring.thymeleaf.cache = true
spring.thymeleaf.check-template = true
spring.thymeleaf.check-template-location = true
spring.thymeleaf.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.template-resolver-order=1
을하지만 같은 No mapping found
메시지가 계속.
32190 [http-nio-8081-exec-2] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/central/css/app.css] in DispatcherServlet with name 'dispatcherServlet'
여기에 표시되지 않는 항목은 무엇입니까?
이것은 첫 번째 접근 방식 이었지만 작동하지 않았습니다. 나는 아주 기본적인 프로젝트 구조를 사용하고있다. Spring Boot는이 문제를 정말로 가지고 있어야한다 ... – gtludwig
위의 속성을 추가 할 때 어떤 오류가 발생합니까? – dimitrisli
spring.resources.static-locations = classpath :/resources/static/css /, classpath :/resources/static/images /, classpath :/resources/static/js /''를'application.properties'에 추가하고 있습니다. '51669 [http-nio-8081-exec-8] WARN osweb.servlet.PageNotFound - DispatcherServlet의 URI가 'dispatcherServlet'인 HTTP 요청 (/central/css/app.css)에 대해 매핑이 없습니다. – gtludwig