2017-10-17 193 views
0

我想从Thymeleaf 2.1.3迁移到3.0.8。我更新了pom.xml文件,就像您可以在下面看到的最新版本的资源一样。如果我尝试将战争文件部署到Jboss,我得到一个BeanCreationException。详细的Stacktrace你可以在下面找到。Thymeleaf从2迁移到3使用thymeleaf-extras-conditionalcomments获得例外

我猜这个异常是由于在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 
+0

看起来像是类路径中不同版本库的混合。 –

回答

1

条件注释现在被提供作为Thymeleaf芯(因为版本3)的一部分。您可以简单地删除该依赖关系。