将 Spring Boot 版本升级至2.2到2.3

Spring Boot版本升级 2.2 至 2.3 的备忘录

我一直忽略升级,所以打算慢慢来处理,这是我的备忘录。

目前的环境为:
Spring Boot: 2.2
Gradle: 6.0.1
Kotlin: 1.4

 

首先,修正build.gradle.kts文件中Spring Boot的版本。

plugins {
//	id("org.springframework.boot") version "2.2.2.RELEASE"
	id("org.springframework.boot") version "2.3.12.RELEASE"
	kotlin("jvm") version "1.4.10"
}

2. 我们会一边不断构建一边排除错误。

我用gradle的版本被批评了。

$ ./gradlew build                                        

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/yukiyoshimura/dev/awba/awba-management/build.gradle.kts' line: 4

* What went wrong:
An exception occurred applying plugin request [id: 'org.springframework.boot', version: '2.3.12.RELEASE']
> Failed to apply plugin [id 'org.springframework.boot']
   > Spring Boot plugin requires Gradle 5 (5.6.x only) or Gradle 6 (6.3 or later). The current version is Gradle 6.0.1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

将gradle-wrapper.properties中的gradle版本更改为6.3或更高版本。

# distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
  distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip

在发展部被责备。

$ ./gradlew build
Downloading https://services.gradle.org/distributions/gradle-6.3-bin.zip
.................................................................................................

Welcome to Gradle 6.3!


Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :
e: /Users/yukiyoshimura/dev/awba/awba-management/build.gradle.kts:30:15: Type mismatch: inferred type is NamedDomainObjectProvider<Configuration> but Configuration! was expected

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/yukiyoshimura/dev/awba/awba-management/build.gradle.kts' line: 30

* What went wrong:
Script compilation error:

  Line 30:              extendsFrom(developmentOnly)
                         ^ Type mismatch: inferred type is NamedDomainObjectProvider<Configuration> but Configuration! was expected

1 error

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 42s
~/dev/awba/awba-management (develop *=)

由于不再需要,可以删除 build.gradle.kts 中关于 spring boot 的 developmentOnly 定义。

需要删除的是下面已经注释掉的部分。

//val developmentOnly by configurations.creating
configurations {
//	runtimeClasspath {
//		extendsFrom(developmentOnly)
//	}
}

// 上記を消すだけでちゃんとdependncies内では developmentOnlyが使える
dependencies {
	developmentOnly("org.springframework.boot:spring-boot-devtools")
}

 

未解决的参考:被要求进行验证时发生了怒气。

在`build.gradle.kts`文件的`dependencies`部分添加以下内容。

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-validation")
}

 

在进行测试时,读取个人资料时出现错误。

我正在进行以下的声明。

@SpringBootTest
@ActiveProfiles("test")
class Test {
}

发生了错误。

IllegalArgumentException: Could not resolve placeholder 'spring.profiles.active' in value "${spring.profiles.active}"

应对

@SpringBootTest("spring.profiles.active:test")
class Test{
}

 

这就是以上的内容。我打算逐步提升版本。

广告
将在 10 秒后关闭
bannerAds