html - Link base "assetscssstyle.css" cannot be context relative (...) - Stack Overflow

A ton of questions have been asked about connecting Thymeleaf + CSS and Spring Boot. I could not find a

A ton of questions have been asked about connecting Thymeleaf + CSS and Spring Boot. I could not find any that addressed this problem with Ktor.

I have this template:

<!DOCTYPE html>
<html xmlns:th="; lang="en">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" th:href="@{/assets/css/style.css}">
</head>
<body>
...
</body>
</html>

This is what the file structure looks like:

src/main/resources/assets/css/style.css
src/main/resources/templates/thymeleaf/books.html

The templating plugin is set up in the following way:

fun Application.configureTemplating() {
  install(Thymeleaf) {
    setTemplateResolver(ClassLoaderTemplateResolver().apply {
      prefix = "templates/thymeleaf/"
      suffix = ".html"
      characterEncoding = "utf-8"
    })
  }
}

This setup works fine without linking CSS, but when trying to link CSS, this error occurs:

.thymeleaf.exceptions.TemplateProcessingException: Link base "/assets/css/style.css" cannot be context relative (/...) unless the context used for executing the engine implements the .thymeleaf.context.IWebContext interface (template: "books" - line 5, col 26)

Please help me solve this problem. Thanks in advance

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745648671a4638125.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信