Skip to content

Commit 699dfc5

Browse files
committed
Improve Kotlin ref doc structure
Issue: SPR-15659
1 parent 5ae35f6 commit 699dfc5

File tree

1 file changed

+75
-70
lines changed

1 file changed

+75
-70
lines changed

src/docs/asciidoc/kotlin.adoc

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -148,49 +148,12 @@ to know if a bean is required or not. `@Autowired lateinit var foo: Foo` implies
148148
of type `Foo` must be registered in the application context while `@Autowired lateinit var foo: Foo?`
149149
won’t raise an error if such bean does not exist.
150150

151-
== WebFlux functional DSL
151+
== Bean definition DSL
152152

153-
Spring Framework 5 comes with a
154-
{doc-root}/spring-framework/docs/{spring-version}/kdoc-api/spring-framework/org.springframework.web.reactive.function.server/-router-function-dsl/[Kotlin routing DSL]
155-
that allows you to leverage the <<reactive-web#webflux-fn,WebFlux functional API>> with clean and idiomatic Kotlin code:
156-
157-
[source,kotlin]
158-
----
159-
router {
160-
accept(TEXT_HTML).nest {
161-
GET("/") { ok().render("index") }
162-
GET("/sse") { ok().render("sse") }
163-
GET("/users", userHandler::findAllView)
164-
}
165-
"/api".nest {
166-
accept(APPLICATION_JSON).nest {
167-
GET("/users", userHandler::findAll)
168-
}
169-
accept(TEXT_EVENT_STREAM).nest {
170-
GET("/users", userHandler::stream)
171-
}
172-
}
173-
resources("/**", ClassPathResource("static/"))
174-
}
175-
----
176-
177-
[NOTE]
178-
====
179-
This DSL is programmatic, thus also allows custom registration logic of beans via `if` expression,
180-
`for` loop or any other Kotlin constructs. That can be useful when routes need to be registered
181-
depending on dynamic data, for example created via the backoffice.
182-
====
183-
184-
See https://github.com/mixitconf/mixit/tree/bad6b92bce6193f9b3f696af9d416c276501dbf1/src/main/kotlin/mixit/web/routes[MiXiT project routes]
185-
for a concrete example.
186-
187-
188-
== Functional bean definition DSL
189-
190-
Spring Framework 5 introduces a new way to register beans using lambda as an alternative
191-
to XML or JavaConfig with `@Configuration` and `@Bean`. In a nutshell, it makes it possible
192-
to register beans with a `Supplier` lambda that acts as a `FactoryBean`. It is very efficient
193-
and does not require any reflection or CGLIB proxies.
153+
Spring Framework 5 introduces a new way to register beans in a functional way using lambda
154+
as an alternative to XML or JavaConfig with `@Configuration` and `@Bean`. In a nutshell,
155+
it makes it possible to register beans with a lambda that acts as a `FactoryBean`.
156+
It is very efficient and does not require any reflection or CGLIB proxies.
194157

195158
In Java you will for example write:
196159

@@ -282,7 +245,45 @@ see https://jira.spring.io/browse/SPR-13779[SPR-13779] and https://github.com/sp
282245
for more details and up to date informations.
283246
====
284247

285-
== Kotlin Script templates
248+
== Web
249+
250+
=== WebFlux Functional DSL
251+
252+
Spring Framework 5 comes with a
253+
{doc-root}/spring-framework/docs/{spring-version}/kdoc-api/spring-framework/org.springframework.web.reactive.function.server/-router-function-dsl/[Kotlin routing DSL]
254+
that allows you to leverage the <<reactive-web#webflux-fn,WebFlux functional API>> with clean and idiomatic Kotlin code:
255+
256+
[source,kotlin]
257+
----
258+
router {
259+
accept(TEXT_HTML).nest {
260+
GET("/") { ok().render("index") }
261+
GET("/sse") { ok().render("sse") }
262+
GET("/users", userHandler::findAllView)
263+
}
264+
"/api".nest {
265+
accept(APPLICATION_JSON).nest {
266+
GET("/users", userHandler::findAll)
267+
}
268+
accept(TEXT_EVENT_STREAM).nest {
269+
GET("/users", userHandler::stream)
270+
}
271+
}
272+
resources("/**", ClassPathResource("static/"))
273+
}
274+
----
275+
276+
[NOTE]
277+
====
278+
This DSL is programmatic, thus also allows custom registration logic of beans via `if` expression,
279+
`for` loop or any other Kotlin constructs. That can be useful when routes need to be registered
280+
depending on dynamic data, for example created via the backoffice.
281+
====
282+
283+
See https://github.com/mixitconf/mixit/tree/bad6b92bce6193f9b3f696af9d416c276501dbf1/src/main/kotlin/mixit/web/routes[MiXiT project routes]
284+
for a concrete example.
285+
286+
=== Kotlin Script templates
286287

287288
As of version 4.3, Spring Framework provides a
288289
http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/view/script/ScriptTemplateView.html[ScriptTemplateView]
@@ -315,25 +316,7 @@ ${include("footer")}
315316
See https://github.com/sdeleuze/kotlin-script-templating[kotlin-script-templating] example
316317
project for more details.
317318

318-
== Getting started
319-
320-
The easiest way to start a new Spring Framework 5 project in Kotlin is to create a new Spring
321-
Boot 2 project on https://start.spring.io/#!language=kotlin[start.spring.io].
322-
323-
It is also possible to create a standalone WebFlux project as described in
324-
https://spring.io/blog/2017/08/01/spring-framework-5-kotlin-apis-the-functional-way[this blog post].
325-
326-
=== Choosing your web flavor
327-
328-
Spring Framework now comes with 2 different web stacks: <<web#mvc,Spring MVC>> and
329-
<<reactive-web#spring-web-reactive,Spring WebFlux>>.
330-
331-
Spring WebFlux is recommended if you want to create applications that will deal with latency,
332-
long-lived connections, streaming scenarios or simply if you want to use the web functional
333-
Kotlin DSL.
334-
335-
For other use cases, Spring MVC and its annotation-based programming model is a perfectly
336-
valid and fully supported choice.
319+
== Spring projects in Kotlin
337320

338321
=== Final by default
339322

@@ -482,47 +465,69 @@ class IntegrationTests {
482465
}
483466
----
484467

485-
=== Resources
468+
== Getting started
469+
470+
=== start.spring.io
471+
472+
The easiest way to start a new Spring Framework 5 project in Kotlin is to create a new Spring
473+
Boot 2 project on https://start.spring.io/#!language=kotlin[start.spring.io].
474+
475+
It is also possible to create a standalone WebFlux project as described in
476+
https://spring.io/blog/2017/08/01/spring-framework-5-kotlin-apis-the-functional-way[this blog post].
477+
478+
=== Choosing your web flavor
479+
480+
Spring Framework now comes with 2 different web stacks: <<web#mvc,Spring MVC>> and
481+
<<reactive-web#spring-web-reactive,Spring WebFlux>>.
482+
483+
Spring WebFlux is recommended if you want to create applications that will deal with latency,
484+
long-lived connections, streaming scenarios or simply if you want to use the web functional
485+
Kotlin DSL.
486+
487+
For other use cases, Spring MVC and its annotation-based programming model is a perfectly
488+
valid and fully supported choice.
489+
490+
== Resources
486491

487492
* http://kotlinlang.org/docs/reference/[Kotlin language reference]
488493
* http://slack.kotlinlang.org/[Kotlin Slack] (with a dedicated #spring channel)
489494
* https://try.kotlinlang.org/[Try Kotlin in your browser]
490495
* https://blog.jetbrains.com/kotlin/[Kotlin blog]
491496
* https://kotlin.link/[Awesome Kotlin]
492497

493-
==== Blog posts
498+
=== Blog posts
494499

495500
* https://spring.io/blog/2016/02/15/developing-spring-boot-applications-with-kotlin[Developing Spring Boot applications with Kotlin]
496501
* https://spring.io/blog/2016/03/20/a-geospatial-messenger-with-kotlin-spring-boot-and-postgresql[A Geospatial Messenger with Kotlin, Spring Boot and PostgreSQL]
497502
* https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0[Introducing Kotlin support in Spring Framework 5.0]
498503
* https://spring.io/blog/2017/08/01/spring-framework-5-kotlin-apis-the-functional-way[Spring Framework 5 Kotlin APIs, the functional way]
499504

500-
==== Examples
505+
=== Examples
501506

502507
* https://github.com/sdeleuze/spring-boot-kotlin-demo[spring-boot-kotlin-demo]: regular Spring Boot + Spring Data JPA project
503508
* https://github.com/mixitconf/mixit[mixit]: Spring Boot 2 + WebFlux + Reactive Spring Data MongoDB
504509
* https://github.com/sdeleuze/spring-kotlin-functional[spring-kotlin-functional]: standalone WebFlux + functional bean definition DSL
505510

506-
==== Tutorials
511+
=== Tutorials
507512

508513
* https://kotlinlang.org/docs/tutorials/spring-boot-restful.html[Creating a RESTful Web Service with Spring Boot]
509514

510-
==== Issues
515+
=== Issues
511516

512517
Here is a list of pending issues related to Spring + Kotlin support.
513518

514-
===== Spring Framework
519+
==== Spring Framework
515520

516521
* https://jira.spring.io/browse/SPR-15413[Add support for Kotlin coroutines]
517522

518-
===== Spring Boot
523+
==== Spring Boot
519524

520525
* https://github.com/spring-projects/spring-boot/issues/5537[Improve Kotlin support]
521526
* https://github.com/spring-projects/spring-boot/issues/8762[Allow @ConfigurationProperties binding for immutable POJOs]
522527
* https://github.com/spring-projects/spring-boot/issues/8511[Provide support for Kotlin KClass parameter in `SpringApplication.run()`]
523528
* https://github.com/spring-projects/spring-boot/issues/8115[Expose the functional bean registration API via `SpringApplication`]
524529

525-
===== Kotlin
530+
==== Kotlin
526531

527532
* https://youtrack.jetbrains.com/issue/KT-6380[Parent issue for Spring Framework support]
528533
* https://youtrack.jetbrains.com/issue/KT-15667[Support "::foo" as a short-hand syntax for bound callable reference to "this::foo"]

0 commit comments

Comments
 (0)