胸腺从2号迁移到3号,使用胸腺附加条件注释时出现异常



我想从Thymelaf 2.1.3迁移到3.0.8。我用最新版本的资源更新了pom.xml文件,如下所示。如果我试图将war文件部署到Jboss,我会得到一个BeanCreationException。您可以在下面找到详细的Stacktrace。

我猜异常是由于ConditionalCommentsDialect的超类构造函数中缺少属性而引发的。ConditionalCommentsDialect正在扩展org.thymelaf.dialect.AbstractDialect,并且在Thymelaf 3版本中更改了构造函数。似乎条件注释对话框与Thymelaf 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

条件注释现在作为Thymelaf核心的一部分提供(自版本3以来)。您可以简单地删除该依赖项。

最新更新