Thymeleaf从2到3的迁移因使用thymeleaf-extras-conditionalcomments而异常

时间:2017-10-17 09:42:39

标签: spring-mvc thymeleaf

我想从Thymeleaf 2.1.3迁移到3.0.8。我更新了pom.xml文件,就像你在下面看到的最新版本的resoucres一样。如果我尝试将war文件部署到Jboss,我将收到BeanCreationException。您可以在下面找到详细的Stacktrace。

我想由于ConditionalCommentsDialect的超类构造函数中缺少属性而引发异常。 ConditionalCommentsDialect正在扩展org.thymeleaf.dialect.AbstractDialect,并且在Thymeleaf 3版本中更改了构造函数。似乎ConditionalCommentsDialect与Thymeleaf 3不兼容。那么我的假设是对的吗?任何想法如何解决这个问题?提前谢谢。

的pom.xml

<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
  <version>3.0.8.RELEASE</version>
</dependency>

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

<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf-testing</artifactId>
  <version>3.0.3.RELEASE</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.attoparser</groupId>
  <artifactId>attoparser</artifactId>
  <version>2.0.4.RELEASE</version>
</dependency>

<dependency>
  <groupId>org.thymeleaf.extras</groupId>
  <artifactId>thymeleaf-extras-conditionalcomments</artifactId>
  <version>2.1.2.RELEASE</version>
</dependency>

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

弹簧配置文件

<util:set id="extraDialects">
  <bean class="nz.net.ultraq.thymeleaf.LayoutDialect"/>
  <bean class="org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect"/>
</util:set>

<bean id="templateResolver"
      class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver"
      p:prefix="classpath:/views/" p:suffix=".html"
      p:templateMode="HTML5" p:characterEncoding="UTF-8"/>

<bean id="templateEngine"
      class="org.thymeleaf.spring4.SpringTemplateEngine"
      p:templateResolver-ref="templateResolver"
      p:extraDialects-ref="extraDialects"/>

<bean id="viewResolver"
      class="org.thymeleaf.spring4.view.ThymeleafViewResolver"
      p:templateEngine-ref="templateEngine"
      p:characterEncoding="UTF-8"/>

异常

Error creating bean with name 'extraDialects': Cannot create inner bean org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect#503d1586' of type [org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect] while setting bean property 'sourceSet' with key [1];
    nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect#503d1586' defined in class path resource [spring-webmvc.xml]: Instantiation of bean failed;
    nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect]: Constructor threw exception;
    nested exception is java.lang.NoSuchMethodError: org.thymeleaf.dialect.AbstractDialect: method <init>()V not found

1 个答案:

答案 0 :(得分:2)

条件评论现在作为Thymeleaf核心的一部分提供(从版本3开始)。您可以简单地删除该依赖项。