【问题标题】:Spring boot dependencies could not be resolved无法解决 Spring Boot 依赖项
【发布时间】:2018-05-13 10:20:11
【问题描述】:

我正在 IntelliJ 中创建 gradle spring boot 项目,但我无法解决一些依赖项。

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

build.gradle 看起来像

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile "joda-time:joda-time:2.2"
    compile "log4j:log4j:1.2.16"
    compile "org.mongodb:mongo-java-driver:1.3"
    compile "org.springframework:spring-core:5.0.2.RELEASE"
    compile "org.springframework:spring-context:3.0.2.RELEASE"
    compile "org.springframework:spring-web:3.0.4.RELEASE"
    compile "org.springframework:spring-webmvc:2.5.2"
    compile "org.jetbrains:annotations:13.0"
    compile "com.google.guava:guava:23.4-jre"
    compile "org.springframework.boot:spring-boot-autoconfigure:1.5.6.RELEASE"
}

我尝试了各种版本的 spring-boot 依赖项,但找不到缺少的内容。任何帮助表示赞赏。

【问题讨论】:

  • 你是不是错过了 spring-boot 插件?
  • 停止混合 spring 版本...您正在混合 5.0.2、3.0.2 和 2.5.2 永远不要混合框架的版本。
  • 在 Spring Boot 中,您甚至不需要为常见依赖项指定版本。 gradle 插件将为您处理版本管理,它将为您提供正确(且兼容)的版本。

标签: spring spring-boot intellij-idea gradle intellij-14


【解决方案1】:

不要试图通过疯狂的猜测来弄清楚事情,而是使用已有的样本,例如this one。

最好的起点是官方 Spring Boot Getting Started Guide,它还包含 Gradle 的示例(和简单)构建配置。

【讨论】:

  • 另外,启动 Spring Boot 项目的一个好方法是在start.spring.io 生成它。您可以选择 Gradle 选项并添加您需要的启动器,它会生成初始的“builderplate”。
猜你喜欢
  • 2015-05-10
  • 2020-12-02
  • 2017-11-12
  • 2012-01-12
  • 1970-01-01
  • 1970-01-01
  • 2019-01-27
  • 2019-07-13
  • 2017-10-11
相关资源
最近更新 更多