将Spring Boot应用程序升级到最新版本

And*_*ser 3 spring build.gradle spring-boot

我有一个基于
Spring Framework 4.3.7.RELEASE和的Spring Boot项目Spring Boot 1.5.2.RELEASE
我使用Java配置方法。如何将这个项目升级到最新版本的Spring Boot和Spring Framework(Spring Boot 2.xSpring Framework 5.x)?我已经签出了此页面,但不幸的是,这对我没有真正的帮助。很高兴收到与此有关的任何进一步指导。

这是我的build.gradle文件的样子:

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

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

version = '0.1.0-alpha.2'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

bootRun.systemProperties = System.properties

springBoot {
    executable = true
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('mysql:mysql-connector-java')
    compile('org.modelmapper:modelmapper:1.1.0')
    compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
    testCompile('org.modelmapper:modelmapper:1.1.0')
}
Run Code Online (Sandbox Code Playgroud)

dun*_*nni 7

进行升级的第一步是仅增加的版本spring-boot-starter-parent。在您使用Gradle的情况下,它将是property中的版本springBootVersion

对于Spring Boot 2,需要特别注意的是,还没有最终版本,因此您必须包括Spring Boot中的里程碑或快照存储库。您可以在以下网址找到这些URL:https : //docs.spring.io/spring-boot/docs/2.0.0.M4/reference/htmlsingle/#getting-started-first-application-pom,尽管该文档适用于Maven。

Gradle的正确设置如下所示:

buildscript {
    ext {
        springBootVersion = '2.0.0.M6'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}
Run Code Online (Sandbox Code Playgroud)