【问题标题】:Thymeleaf + springboot not working togetherThymeleaf + spring boot 不能一起工作
【发布时间】:2017-02-28 08:02:47
【问题描述】:

我想将 springboot 与 thymeleaf 一起使用。我创建了一个控制器,如下所示:

我有这样的项目结构:

package com.mbtimeet.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class HomeController {

@RequestMapping("/hello")
public String index(){
    return "index";
}
}

我有一个 index.html:

<!DOCTYPE html>
<html xmlns:th=“http://www.thymeleaf.org”         xmlns="http://www.w3.org/1999/html">
<head>
</head>
<body>
Hi there.
</body>
</html>

而且它只是不工作。打开“http://localhost:8080/hello”页面后出现异常。

日志:http://pastebin.com/MLPgpqph

构建.gradle:

buildscript {
    ext {
        springBootVersion = '1.4.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

jar {
    baseName = 'mbti-meet'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile("org.springframework.boot:spring-boot-devtools")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

错误:

2016-10-18 22:58:15.413 ERROR 4896 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template="index", line 2 - column 16] with root cause

我跟着一个教程,唯一的区别是用户使用了maven。

【问题讨论】:

  • 请复制您帖子中的错误;只是错误而不是整个日志。

标签: jsp spring-mvc intellij-idea spring-boot thymeleaf


【解决方案1】:

日志消息会准确地告诉您问题所在。由于某种原因,当您创建 index.html 文件时,xmlns:th=“http://www.thymeleaf.org” 得到了 UTF-8 格式的引号,而不是 ascii 的 "。因此,Thymeleaf 在解析文件时遇到问题。将属性更新为xmlns:th="http://www.thymeleaf.org"

【讨论】:

  • 我得到了同样的错误,我解决了添加 xmlns:th="thymeleaf.org 作为@ShawClark 的建议,我删除了标签
猜你喜欢
  • 1970-01-01
  • 2017-03-23
  • 2020-11-05
  • 2018-12-24
  • 2014-07-04
  • 2015-04-26
  • 2019-08-07
  • 2018-06-03
相关资源
最近更新 更多