2016-09-06 163 views
3

我试图运行Spring Boot和Thymeleaf的例子。我得到这个错误:春季启动和Thymeleaf Neko HTML错误

There was an unexpected error (type=Internal Server Error, status=500). Cannot perform conversion to XML from legacy HTML: The nekoHTML library is not in classpath. nekoHTML 1.9.15 or newer is required for processing templates in "LEGACYHTML5" mode

这是我的依赖关系:

<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 

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

回答

5

Maven的,简单的添加这种依赖性:

MVN依赖性:树-Dincludes = net.sourceforge.nekohtml:nekohtml

结果没有

似乎弹簧boot-百里香不包括nekohtml图书馆。


对于gradle这个,你会发现你在https://mvnrepository.com/artifact/net.sourceforge.nekohtml/nekohtml想要的版本,并找到gradle这个包括这样的脚本:

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

你对。 Spring Boot确实可以管理nekohtml依赖项(所以你可以在没有版本的情况下添加依赖项),但是thymeleaf starter默认不会启用它。 –

+1

对我来说令人惊讶:)似乎Neko HTML是Thymeleaf的必须品,但它并未包含在spring-boot-thymeleaf中。我以为我错过了什么。谢谢! – kamaci

+0

例如,如果您使用HTML5模式,则根本不需要Neko库。作为一个可选的依赖关系,只有在项目需要时才会包含更好的结果。 –

0

添加到您的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> 
+0

你的回答并不完全回答OP的问题。除了告诉“添加这个”之外,你应该解释为什么添加它,以及它是否解决了手头的问题。 – ZF007