With Spring 5 now having dedicated Kotlin support, let’s have a look into the features that are designed to make these technologies work seamless together.
5 introduces non-null API declaration for all packages ▸ Explicitly nullable arguments and return values annotated as such ▸ ➜ Spring framework APIs = null-safe from Kotlin side (Kotlin 1.1.50+)
5 introduces non-null API declaration for all packages ▸ Explicitly nullable arguments and return values annotated as such ▸ ➜ Spring framework APIs = null-safe from Kotlin side (Kotlin 1.1.50+) @NonNullApi package org.springframework.core; /** * Return the "Cache-Control" header value. * @return {@code null} if no directive was added, or the header value otherwise */ @Nullable public String getHeaderValue()
// "GET /foo" and "GET /foo?bar=baz" are allowed @GetMapping("/foo") fun foo(@RequestParam bar: String?) = ... // "GET /foo?bar=baz" is allowed and "GET /foo" will error @GetMapping("/foo") fun foo(@RequestParam bar: String) = ...
StepVerifier APIs ▸ Kotlin extensions ▸ any class instance to Mono instance with foo.toMono() ▸ create Flux from Java 8 Streams wih stream.toFlux() ▸ extensions for Iterable, CompletableFuture, Throwable
by default ➜ add open keyword on each class / member functions of Spring beans ▸ @Component @Async @Transactional @Cacheable ▸ Meta-annotations support: @Configuration, @Controller, @RestController, @Service, @Repository