spring-boot

Spring Boot (Kotlin)

Idiomatic Kotlin patterns for Spring Boot applications

Kotlin
framework
Default
Used by 230 projects

Details

Language / Topic
kotlinKotlin
Category
framework
Compatible Frameworks
spring-boot
spring

Rules

balanced
- Use Kotlin data classes for DTOs and `@ConfigurationProperties` — Spring Boot auto-maps YAML/properties to constructor params.
- Use constructor injection (Kotlin's primary constructor) — no `@Autowired` needed when there's a single constructor.
- Use Kotlin coroutines with Spring WebFlux: `suspend fun` in controllers returns reactive responses without callback chains.
- Use `@Service`, `@Repository`, `@RestController` stereotypes — combine with Kotlin's `object` declarations for singletons sparingly.
- Use Kotlin coroutines with Spring WebFlux: define endpoints as `suspend fun` for non-blocking I/O.
- Use `@ConfigurationProperties` with Kotlin data classes for type-safe, immutable configuration binding.
- Use Kotlin DSL for Spring Security configuration: `http { authorizeRequests { authorize("/api/**", authenticated) } }`.
- Use extension functions to add reusable behavior to Spring beans without inheritance.
- Use sealed classes for domain error hierarchies and map them in `@ControllerAdvice` handlers.