2016-09-06 158 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