@@ -11,7 +11,7 @@ https://kotlinlang.org[Kotlin] is a statically-typed language targeting the JVM
11
11
code while providing a very good https://kotlinlang.org/docs/reference/java-interop.html[interoperability] with libraries
12
12
written in Java.
13
13
14
- Spring Framework 5 introduces first-class support for Kotlin in order to allow developers to write Spring + Kotlin
14
+ Spring Framework 5 introduces first-class support for Kotlin and allows developers to write Spring + Kotlin
15
15
applications almost like if Spring Framework was a native Kotlin framework.
16
16
17
17
== Requirements ==
@@ -23,7 +23,7 @@ and https://bintray.com/bintray/jcenter/org.jetbrains.kotlin%3Akotlin-reflect[`k
23
23
to be present on the classpath. They are provided by default if you bootstrap a Kotlin project on
24
24
https://start.spring.io/#!language=kotlin[start.spring.io].
25
25
26
- == Kotlin extensions for Spring API
26
+ == Extensions
27
27
28
28
Thanks to its great https://kotlinlang.org/docs/reference/java-interop.html[Java interoperability]
29
29
and to https://kotlinlang.org/docs/reference/extensions.html[Kotlin extensions], Spring
@@ -73,7 +73,7 @@ Other libraries like Reactor or Spring Data also provide Kotlin extensions for t
73
73
in order to allow a better Kotlin development experience.
74
74
====
75
75
76
- == Null-safety of Spring API
76
+ == Null-safety
77
77
78
78
One of Kotlin's key features is https://kotlinlang.org/docs/reference/null-safety.html[null-safety]
79
79
which allows to deal with `null` values at compile time rather than bumping into the famous
@@ -115,7 +115,7 @@ Other libraries like Reactor or Spring Data leverage these annotations to provid
115
115
null-safe APIs for Kotlin developers.
116
116
====
117
117
118
- == Support for Kotlin classes
118
+ == Classes
119
119
120
120
Spring Framework 5 now supports various Kotlin constructs like instantiating Kotlin classes
121
121
via primary constructors, immutable classes data binding and function optional parameters
@@ -131,7 +131,7 @@ Kotlin module.
131
131
As of Spring Boot 2.0, Jackson Kotlin module is automatically provided via the JSON starter.
132
132
====
133
133
134
- == Leveraging null-safety in Spring annotations
134
+ == Annotations
135
135
136
136
Spring Framework also takes advantage of https://kotlinlang.org/docs/reference/null-safety.html[Kotlin null-safety]
137
137
to determine if an HTTP parameter is required without having to define explicitly the `required` attribute.
@@ -144,11 +144,11 @@ to know if a bean is required or not. `@Autowired lateinit var foo: Foo` implies
144
144
of type `Foo` must be registered in the application context while `@Autowired lateinit var foo: Foo?`
145
145
won’t raise an error if such bean does not exist.
146
146
147
- == Spring WebFlux functional DSL
147
+ == WebFlux functional DSL
148
148
149
149
Spring Framework 5 comes with a
150
150
{doc-root}/spring-framework/docs/{spring-version}/kdoc-api/spring-framework/org.springframework.web.reactive.function.server/-router-function-dsl/[Kotlin routing DSL]
151
- that allows you to leverage the <<webflux-fn,WebFlux functional API] with clean and idiomatic Kotlin code:
151
+ that allows you to leverage the <<reactive-web# webflux-fn,WebFlux functional API>> with clean and idiomatic Kotlin code:
152
152
153
153
[source,kotlin]
154
154
----
@@ -278,7 +278,7 @@ see https://jira.spring.io/browse/SPR-13779[SPR-13779] and https://github.com/sp
278
278
for more details and up to date informations.
279
279
====
280
280
281
- == Kotlin Script based templates
281
+ == Kotlin Script templates
282
282
283
283
As of version 4.3, Spring Framework provides a
284
284
http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/view/script/ScriptTemplateView.html[ScriptTemplateView]
@@ -319,10 +319,10 @@ Boot 2 project on https://start.spring.io/#!language=kotlin[start.spring.io].
319
319
It is also possible to create a standalone WebFlux project as described in
320
320
https://spring.io/blog/2017/08/01/spring-framework-5-kotlin-apis-the-functional-way[this blog post].
321
321
322
- === Choose your web flavor
322
+ === Choosing your web flavor
323
323
324
- Spring Framework now comes with 2 different web stacks: <<web.adoc ,Spring MVC>> and
325
- <<reactive-web.adoc ,Spring WebFlux>>.
324
+ Spring Framework now comes with 2 different web stacks: <<web#mvc ,Spring MVC>> and
325
+ <<reactive-web#spring-web-reactive ,Spring WebFlux>>.
326
326
327
327
Spring WebFlux is recommended if you want to create applications that will deal with latency,
328
328
long-lived connections, streaming scenarios or simply if you want to use the web functional
@@ -331,7 +331,7 @@ Kotlin DSL.
331
331
For other use cases, Spring MVC and its annotation-based programming model is a perfectly
332
332
valid and fully supported choice.
333
333
334
- === Classes and member functions final by default
334
+ === Final by default
335
335
336
336
By default, https://discuss.kotlinlang.org/t/classes-final-by-default/166[all classes in Kotlin are `final`].
337
337
The `open` modifier on a class is the opposite of Java's `final`: it allows others to
@@ -360,7 +360,7 @@ annotations are meta-annotated with `@Component`.
360
360
361
361
http://start.spring.io/#!language=kotlin[start.spring.io] enables it by default.
362
362
363
- === What is the recommended way to inject dependencies in Kotlin?
363
+ === Injecting dependencies
364
364
365
365
Try to favor constructor injection with `val` read-only https://kotlinlang.org/docs/reference/properties.html[properties].
366
366
@@ -437,7 +437,7 @@ properties since immutable classes initialized by constructor are not support ye
437
437
See https://github.com/spring-projects/spring-boot/issues/8762[this issue] for more details.
438
438
====
439
439
440
- === Easy testing Kotlin and JUnit 5
440
+ === Testing
441
441
442
442
Kotlin allows to specify meaningful test function names betweeen backticks,
443
443
and as of JUnit 5 Kotlin test classes can use `@TestInstance(TestInstance.Lifecycle.PER_CLASS)`
@@ -478,7 +478,6 @@ class IntegrationTests {
478
478
}
479
479
----
480
480
481
-
482
481
=== Resources
483
482
484
483
* http://kotlinlang.org/docs/reference/[Kotlin language reference]
@@ -504,7 +503,9 @@ class IntegrationTests {
504
503
505
504
* https://kotlinlang.org/docs/tutorials/spring-boot-restful.html[Creating a RESTful Web Service with Spring Boot]
506
505
507
- ==== Pending issues to follow
506
+ ==== Issues
507
+
508
+ Here is a list of pending issues related to Spring + Kotlin support.
508
509
509
510
===== Spring Framework
510
511
0 commit comments