NoSuchMethodError:org.thymeleaf.standard.StandardDialect with spring 4 and thymeleaf 3

时间:2016-08-09 16:12:02

标签: thymeleaf spring-4

嗨,我正在使用带有百叶窗3的弹簧4作为我的项目。我根据他们的文档改变了一切。当我在wildfly 10上运行应用程序时,它显示出一些错误..

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>

3 个答案:

答案 0 :(得分:3)

我不知道你是否解决了这个问题,但你在这里的帖子是我在整个互联网上遇到这个问题的唯一结果。

我花了几个小时才终于找到了原因。出于某种原因,我在项目的/ lib文件夹中有了Thymeleaf 2.14-RELEASE jar。我的IDE(Intellij 2016.2.5)使用的是这个版本,而不是maven拥有的3.0.5-RELEASE版本。 IDE中没有明显暗示这是正在发生的。

主要问题是来自2.14的StandardDialect没有构造函数(因此出现了奇怪的错误)但是3.0.5中的那个没有。

我绞尽脑汁,因为这个错误没有合理的理由,我希望这可以拯救那些可怜的灵魂。

答案 1 :(得分:0)

我遇到了同样的问题,我刚刚删除了所有额外的thymeleaf依赖项,只是将它添加到pom.xml并且适用于我。

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

答案 2 :(得分:0)

同样的问题,在我删除此问题后对我有用:

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