【问题标题】:Thymeleaf Configuration - Not able to import org.thymeleaf.spring4.*Thymeleaf 配置 - 无法导入 org.thymeleaf.spring4.*
【发布时间】:2020-02-05 10:48:46
【问题描述】:

我在我的 spring-boot web 应用程序中使用 Thymeleaf,并且我正在尝试将 Thymelief 已经提供的功能用于 Spring Boot 项目。但是,我无法导入 org.thymeleaf.spring4.* - 实际上,spring4 根本无法识别。我正在使用 Thymeleaf 3.0.11。

其实在我的项目中,使用gradle作为构建自动化工具,添加Thymeleaf如下(在一个多模块的Spring Boot应用中,这个gradle文件对应Thymeleaf模板引擎所在的模块配置):

configurations.all {
    resolutionStrategy {
 ...

        dependencySubstitution {
    ...

            substitute module('org.thymeleaf:thymeleaf') with module('org.thymeleaf:thymeleaf:3.0.11.RELEASE')
        }
    }
}

我希望知道发生这种情况的原因吗?

【问题讨论】:

  • 检查 start.spring.io 并从那里下载项目。如果你想看看哪里出了问题,你可以将它与你当前的项目进行比较。
  • 您确定要spring4而不是spring5吗?

标签: spring-boot spring-mvc thymeleaf


【解决方案1】:

确保你在 pom.xml 中添加了依赖

<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 -->
<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf-spring4</artifactId>
    <version>3.0.11.RELEASE</version>
</dependency>

【讨论】:

  • 感谢您的评论。实际上,我的项目中使用了 gradle,它是这样添加的:...substitute module('org.thymeleaf:thymeleaf') with module('org.thymeleaf:thymeleaf:3.0.11.RELEASE') - 因为 sprig-boot 拉入旧版本。
  • 这是基本的thymeleaf 依赖。你还需要spring依赖
  • 我认为 spring 依赖项已经存在,因为它是 spring 项目,正如用户所说的那样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
  • 2013-10-25
  • 1970-01-01
  • 2018-12-22
  • 1970-01-01
  • 2018-01-13
相关资源
最近更新 更多