【问题标题】:Spring Boot and Thymeleaf Neko HTML ErrorSpring Boot 和 Thymeleaf Neko HTML 错误
【发布时间】:2017-01-14 07:31:35
【问题描述】:

我正在尝试使用 Spring Boot 和 Thymeleaf 运行示例。我得到了那个错误:

出现意外错误(类型=内部服务器错误, 状态=500)。无法执行从旧版 HTML 到 XML 的转换: nekoHTML 库不在类路径中。 nekoHTML 1.9.15 或更新版本是 在“LEGACYHTML5”模式下处理模板时需要

这些是我的依赖项:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <version>2.1.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

这是我的应用程序属性:

spring.thymeleaf.cache=false
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html

当我添加 Neko HTML 依赖时,错误消失了。但是,它应该通过我当前的依赖项包含在内。可能是什么问题?

【问题讨论】:

    标签: java spring spring-mvc spring-boot thymeleaf


    【解决方案1】:

    将此添加到您的pom.xml

    <!-- https://mvnrepository.com/artifact/net.sourceforge.nekohtml/nekohtml -->
    <dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
        <version>1.9.22</version>
    </dependency>
    

    【讨论】:

    • 你的回答并没有完全回答OP的问题。除了告诉“添加这个”之外,您还应该解释为什么添加它以及它是否解决了手头的问题。
    【解决方案2】:

    对于 Maven,只需添加此依赖项:

    mvn 依赖:tree -Dincludes=net.sourceforge.nekohtml:nekohtml

    没有结果

    似乎 spring-boot-thymeleaf 不包含 nekohtml 库。


    对于 gradle,你可以在 https://mvnrepository.com/artifact/net.sourceforge.nekohtml/nekohtml 中找到你想要的版本,然后找到 gradle include 脚本如下:

    compile group: 'net.sourceforge.nekohtml', name: 'nekohtml', version: '1.9.22'
    

    【讨论】:

    • 你是对的。 Spring Boot 确实管理了 nekohtml 依赖项(因此您可以在没有版本的情况下添加该依赖项),但 thymeleaf 启动器默认不带它。
    • 让我感到惊讶 :) 似乎 Neko HTML 是 Thymeleaf 的必需品,但它没有包含在 spring-boot-thymeleaf 中。我以为我错过了什么。谢谢!
    • 例如,如果您使用 HTML5 模式,则根本不需要 Neko 库。作为可选依赖项,仅在项目需要时才包含它要好得多。
    猜你喜欢
    • 2018-04-16
    • 2015-10-26
    • 2017-08-29
    • 2021-11-17
    • 2017-06-21
    • 2018-07-08
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    相关资源
    最近更新 更多