JSUG Study Group 2020 Part 1 Spring x Kotlin Share the notes you took when you attended.
It's very simple, but I hope you find it helpful.
Spring Initializr Intellij IDEA (paid version)
Kotlin does not inherit by default, so you need to add the open modifier to the service class. However, if you use Kotlin's allopen plugin or kotlin-spring plugin, it will be treated as open automatically.
By the way, it is set from the beginning in the project generated by Spring Initializr.
Be careful of validation. In the sense of Java
class Body {
@NotNull val value: Int
}
If you write, validation will not be applied.
class Body {
@field:NotNull val value: Int?
}
Write like this.
Bean Definition DSL Router DSL
Linter ktlint so-called Linter and Formatter There is a Gradle plugin. There is also an automatic setting for IntelliJ IDEA.
Kotlin has coroutines. Reactor compatible libraries are official.
・ JetBrains official ・ Very thin, extra functions are left to the 3rd party ・ DSL ・ Non-blocking
Use the extension function expectBody for Kotlin. The assertion library uses AssertJ. (Of course Kotlin compatible) I like the feeling of writing in the method chain.
Also, I'm interested in assertk.
Also supports coroutines.
I'm using a JDBC template. I'm writing raw SQL and steadily mapping it to a class. The exposed is also made by JetBrains and looks good.
Starting with Spring 5.2, Kotlin code has also been added to the official Spring documentation.
Router Functions A new routing method that is different from the traditional annotation base WebFlux.fn → From Spring 5 WebMVC.fn → From Spring 5.2 Functional routing method
MockMvc DSL Cleaner and easier to understand than previous method chains
@ConfigurationProperties Binding to multiple properties at once Relaxed Binding works
From Boot 2.2.1, you can get the setting value with immutable through the constructor with @ConstructorBinding. You now need @Compornent and @EnableAutoConfiguration.
What is a coroutine? -Computation instance that makes it easy to suspend / resume processing ・ Something like a weighing thread ・ Can be described in async / await style ・ The concept of scope makes it easy to manage the dependencies between coroutines. -A conversion module to data types compliant with other Reactive Streams is provided.
WebFlux's support for coroutines has made it possible to use coroutine types instead of reactors, making it more Kotlin-like and easier to parallelize.
Performance is much better if you can program Reactive.
The State of Kotlin Support in Spring is a recommended video
I'm glad I learned a lot about the notes and tips when writing Spring Boot in Kotlin. I will start with Spring Initializr as well.
Also, since the word about Web Flux was at a level I had heard, I understood the concept a little more and decided to write it because it can actually be Java.
Once again, thank you very much to all the speakers and operators.
Recommended Posts