【问题标题】:SpringBoot with Gradle missing dependency for Thymeleaf带有 Gradle 的 Spring Boot 缺少 Thymeleaf 的依赖项
【发布时间】:2016-08-19 15:19:25
【问题描述】:

我正在尝试使用 Thymeleaf 作为我的模板引擎来设置一个非常简单的 Springboot 应用程序。我 %100 确定我的 @Controller 工作正常,但是当我尝试访问默认 url ("/") 时,我得到了可怕的 "Whitelabel" 错误页面。

下面是我的 gradle.build 文件...

buildscript {
     ext { springBootVersion = '1.4.0.RELEASE' }
     repositories { mavenCentral() }
     dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'

jar {
     baseName = 'masterSpringMvc'
     version = '0.0.1-SNAPSHOT'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories { mavenCentral() }

 dependencies {
     compile('org.springframework.boot:spring-boot-starter-web')
     compile('org.springframework.boot:spring-boot-starter-thymeleaf')
     testCompile('org.springframework.boot:spring-boot-starter-test')
 }

eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}

很确定我已正确设置所有内容,因此我继续运行以下构建步骤...

在此之后,我希望在“项目和外部依赖项”中看到 spring-boot-starter-thymeleaf.jar,但它不存在。我对 Gradle 很陌生,并假设构建会引入这个所需的依赖项,然后在启动我的应用程序时它会被“启用”。任何线索我在这里可能做错了什么?

这是我的 .html 页面,我希望在浏览器中看到“测试”。

【问题讨论】:

  • 仅供参考,我花了几分钟时间创建了一个基于 Maven 的项目,该项目完全相同并且工作正常(我对 Maven 非常满意,但想知道我做错了什么Gradle,其 99.9% 与帖子中提到的不引入依赖项有关)

标签: spring thymeleaf


【解决方案1】:

您需要更新依赖项。 在包资源管理器上: -> 右键单击​​您的项目 -> Gradle -> 启用依赖管理 -> 再次右键单击它 -> 刷新依赖

【讨论】:

  • 很抱歉,响应延迟,我只能选择右键单击项目 -> 刷新 Gradle 项目,但这确实起到了作用。那么为什么 Gradle 构建不做同样的事情呢?它到底是干什么用的?只是构建实际可部署的 jar/war?
猜你喜欢
  • 2019-07-26
  • 1970-01-01
  • 2015-05-03
  • 2020-03-13
  • 2014-04-18
  • 2016-09-17
  • 1970-01-01
  • 1970-01-01
  • 2020-03-31
相关资源
最近更新 更多