相关疑难解决方法(0)

解析模板"index"时出错,模板可能不存在,或者任何已配置的模板解析器都可能无法访问

之前已经问过这个问题,但我没有解决我的问题而且我得到了一些奇怪的功能.

如果我将index.html文件放在静态目录中,如下所示:

在此输入图像描述

我在浏览器中收到以下错误:

在此输入图像描述

在我的控制台中:

[THYMELEAF][http-nio-8080-exec-3] Exception processing template "login": 
Exception parsing document: template="login", line 6 - column 3
2015-08-11 16:09:07.922 ERROR 5756 --- [nio-8080-exec-3] 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="login", line 6 - column 3] with root cause

org.xml.sax.SAXParseException: The element type "meta" must be terminated by 
the matching end-tag "</meta>".
Run Code Online (Sandbox Code Playgroud)

但是,如果我将index.html文件移动到templates目录中,我的浏览器中会出现以下错误: 在此输入图像描述

在此输入图像描述

我添加了我的视图解析器:

@Controller
@EnableWebMvc
public class WebController extends WebMvcConfigurerAdapter { …
Run Code Online (Sandbox Code Playgroud)

thymeleaf spring-boot

22
推荐指数
7
解决办法
12万
查看次数

Thymeleaf无法检测spring-boot项目中的模板

我的Spring启动应用程序中有以下项目结构,我想使用Thymeleaf

projectName
    -Gradle-Module1(Spring boot module)
        -build
        -src
            -main
            -resources
                -templates
                    index.html
        build.gradle
    -Gradle-Module2
        ...
    build.gradle
    ...
Run Code Online (Sandbox Code Playgroud)

但是spring-boot找不到我的模板目录并显示警告

Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
Run Code Online (Sandbox Code Playgroud)

PS:我正在使用 @EnableAutoConfiguration

在我的控制器代码中,我正在做类似的事情

@Controller
@EnableAutoConfiguration
public class BaseController {

    @RequestMapping(value = "/")
    public String index() {
        return "index.html";
    }
}
Run Code Online (Sandbox Code Playgroud)

index.html文件只打印你好世界.

所以通常它应该看起来src/resources/templates/(我想的是相同的Gradle模块),但不知怎的,它无法找到它.

当我尝试访问时,localhost:8080 我得到以下错误Error resolving template "index.html", template might not exist or might not be accessible by any of the configured Template Resolvers …

java spring thymeleaf spring-boot

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

spring-boot ×2

thymeleaf ×2

java ×1

spring ×1