Update Kotlin-related reference documentation
See gh-18573
This commit is contained in:
parent
c75b06c76c
commit
c6c9818285
|
|
@ -7614,35 +7614,44 @@ In order to avoid mixing different versions of Kotlin dependencies on the classp
|
|||
With Maven, the Kotlin version can be customized via the `kotlin.version` property and plugin management is provided for `kotlin-maven-plugin`.
|
||||
With Gradle, the Spring Boot plugin automatically aligns the `kotlin.version` with the version of the Kotlin plugin.
|
||||
|
||||
Spring Boot also manages the version of Coroutines dependencies by importing Kotlin
|
||||
Coroutines BOM, which can be customized via the `kotlin-coroutines.version` property.
|
||||
|
||||
TIP: `org.jetbrains.kotlinx:kotlinx-coroutines-reactor` dependency is provided by default
|
||||
if one bootstraps a Kotlin project with at least one Reactive dependency on https://start.spring.io/#!language=kotlin[start.spring.io].
|
||||
|
||||
|
||||
[[boot-features-kotlin-configuration-properties]]
|
||||
=== `@ConfigurationProperties`
|
||||
`@ConfigurationProperties` supports classes with immutable `val` properties as shown in the following example:
|
||||
`@ConfigurationProperties` when used in combination with `@ConstructorBinding` (see the
|
||||
<<boot-features-external-config-constructor-binding,dedicated documentation>> for more details)
|
||||
supports classes with immutable `val` properties as shown in the following example:
|
||||
|
||||
[source,kotlin,indent=0]
|
||||
----
|
||||
@ConfigurationProperties("example.kotlin")
|
||||
@ConstructorBinding
|
||||
data class KotlinExampleProperties(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val myService: MyService
|
||||
)
|
||||
val myService: MyService) {
|
||||
|
||||
data class MyService(
|
||||
val apiToken: String,
|
||||
val uri: URI
|
||||
)
|
||||
data class MyService(
|
||||
val apiToken: String,
|
||||
val uri: URI
|
||||
)
|
||||
}
|
||||
----
|
||||
|
||||
TIP: To generate <<appendix-configuration-metadata.adoc#configuration-metadata-annotation-processor,your own metadata>> using the annotation processor, {kotlin-docs}kapt.html[`kapt` should be configured] with the `spring-boot-configuration-processor` dependency.
|
||||
Note that some features (such as detecting the default value or deperecated items) are not working due to limitations in the model kapt provides.
|
||||
Note that some features (such as detecting the default value or deprecated items) are not working due to limitations in the model kapt provides.
|
||||
|
||||
|
||||
|
||||
[[boot-features-kotlin-testing]]
|
||||
=== Testing
|
||||
While it is possible to use JUnit 4 to test Kotlin code, JUnit 5 is recommended.
|
||||
While it is possible to use JUnit 4 to test Kotlin code, JUnit 5 now provided by default
|
||||
with Spring Boot is recommended.
|
||||
JUnit 5 enables a test class to be instantiated once and reused for all of the class's tests.
|
||||
This makes it possible to use `@BeforeClass` and `@AfterClass` annotations on non-static methods, which is a good fit for Kotlin.
|
||||
|
||||
|
|
@ -7683,6 +7692,7 @@ If you need the `Mockk` equivalent of the Mockito specific <<boot-features-testi
|
|||
* https://github.com/sdeleuze/spring-kotlin-fullstack[spring-kotlin-fullstack]: WebFlux Kotlin fullstack example with Kotlin2js for frontend instead of JavaScript or TypeScript
|
||||
* https://github.com/spring-petclinic/spring-petclinic-kotlin[spring-petclinic-kotlin]: Kotlin version of the Spring PetClinic Sample Application
|
||||
* https://github.com/sdeleuze/spring-kotlin-deepdive[spring-kotlin-deepdive]: a step by step migration for Boot 1.0 + Java to Boot 2.0 + Kotlin
|
||||
* https://github.com/sdeleuze/spring-boot-coroutines-demo[spring-boot-coroutines-demo]: Coroutines sample project
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue