2016-08-09 181 views
0

嗨,我爲我的項目使用了春季4與百里香3。根據他們的文檔,我改變了一切。當我運行wildfly 10的應用程序,它顯示了一些錯誤..NoSuchMethodError:org.thymeleaf.standard.StandardDialect with spring 4 and thymeleaf 3

21:35:15,447 WARN [org.springframework.web.context.support.XmlWebApplicationContext] (ServerService Thread Pool -- 9) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'templateEngine' defined in class path resource [spring/ViewConfig.xml]: Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: org.thymeleaf.standard.StandardDialect.<init>(Ljava/lang/String;Ljava/lang/String;I)V 
21:35:15,458 ERROR [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 9) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'templateEngine' defined in class path resource [spring/ViewConfig.xml]: Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: org.thymeleaf.standard.StandardDialect.<init>(Ljava/lang/String;Ljava/lang/String;I)V 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 

Themeleaf3依賴

<dependency> 
     <groupId>org.thymeleaf</groupId> 
     <artifactId>thymeleaf</artifactId> 
     <version>3.0.1.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.thymeleaf</groupId> 
     <artifactId>thymeleaf-spring4</artifactId> 
     <version>3.0.1.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>nz.net.ultraq.web.thymeleaf</groupId> 
     <artifactId>thymeleaf-layout-dialect</artifactId> 
     <version>1.0.6</version> 
    </dependency> 

模板解析器配置

<bean id="templateResolver" 
     class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> 
     <property name="prefix" value="/WEB-INF/views/" /> 
     <property name="suffix" value=".html" /> 
     <property name="templateMode" value="HTML5" /> 
    </bean> 

    <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"> 
     <property name="templateResolver" ref="templateResolver" /> 
     <property name="dialects"> 
      <set> 
       <bean class="org.thymeleaf.standard.dialect.StandardDialect" /> 
       <bean class="nz.net.ultraq.web.thymeleaf.LayoutDialect" /> 
      </set> 
     </property> 
    </bean> 

    <bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver"> 
     <property name="templateEngine" ref="templateEngine" /> 
    </bean> 

回答

2

我不知道,如果你解決這個,但你在這裏的帖子是我在整個互聯網上獲得這個問題的唯一結果。

我花了幾個小時終於找到我的原因。出於某種原因,我在我的項目的/ lib文件夾中安裝了Thymeleaf 2.14-RELEASE jar。我的IDE(Intellij 2016.2.5)使用的是這個版本,而不是使用maven的3.0.5-RELEASE版本。 IDE內沒有明顯的提示,這是發生。

主要問題是從2.14的StandardDialect沒有構造函數(因此奇怪的錯誤),但3.0.5中的一個。

因爲這個錯誤沒有合乎邏輯的理由,所以我在絞盡腦汁,我希望這可以拯救任何可憐的靈魂。

0

我有同樣的問題,我只是刪除所有額外thymeleaf依賴關係,只是將其添加到pom.xml併爲我工作。

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency>