Labsco
github logo

kotlin-springboot

✓ Official36,200

by github · part of github/awesome-copilot

Spring Boot development patterns and idioms tailored for Kotlin applications. Use primary constructors for dependency injection, data class for DTOs, and the kotlin-jpa plugin to automatically open entity classes without boilerplate. Organize code by feature/domain rather than layer; leverage Kotlin's null-safety to clearly define optional vs. required entity fields. Apply @ConfigurationProperties with data class for type-safe, immutable configuration; use application.yml and Spring Profiles...

🔥🔥🔥🔥✓ VerifiedFreeAdvanced setup
🧩 One of 7 skills in the github/awesome-copilot package — works on its own, and pairs well with its siblings.

Spring Boot development patterns and idioms tailored for Kotlin applications. Use primary constructors for dependency injection, data class for DTOs, and the kotlin-jpa plugin to automatically open entity classes without boilerplate. Organize code by feature/domain rather than layer; leverage Kotlin's null-safety to clearly define optional vs. required entity fields. Apply @ConfigurationProperties with data class for type-safe, immutable configuration; use application.yml and Spring Profiles...

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates — shown here so you can audit it before installing. You don't need to read it to use the skill.

by github

Spring Boot development patterns and idioms tailored for Kotlin applications. Use primary constructors for dependency injection, data class for DTOs, and the kotlin-jpa plugin to automatically open entity classes without boilerplate. Organize code by feature/domain rather than layer; leverage Kotlin's null-safety to clearly define optional vs. required entity fields. Apply @ConfigurationProperties with data class for type-safe, immutable configuration; use application.yml and Spring Profiles... npx skills add https://github.com/github/awesome-copilot --skill kotlin-springboot Download ZIPGitHub36.2k

Spring Boot with Kotlin Best Practices

Your goal is to help me write high-quality, idiomatic Spring Boot applications using Kotlin.

Dependency Injection & Components

  • Primary Constructors: Always use the primary constructor for required dependency injection. It's the most idiomatic and concise approach in Kotlin.

  • Immutability: Declare dependencies as private val in the primary constructor. Prefer val over var everywhere to promote immutability.

  • Component Stereotypes: Use @Service, @Repository, and @RestController annotations just as you would in Java.

Web Layer (Controllers)

  • RESTful APIs: Design clear and consistent RESTful endpoints.

  • Data Classes for DTOs: Use Kotlin data class for all DTOs. This provides equals(), hashCode(), toString(), and copy() for free and promotes immutability.

  • Validation: Use Java Bean Validation (JSR 380) with annotations (@Valid, @NotNull, @Size) on your DTO data classes.

  • Error Handling: Implement a global exception handler using @ControllerAdvice and @ExceptionHandler for consistent error responses.

Service Layer

  • Business Logic: Encapsulate business logic within @Service classes.

  • Statelessness: Services should be stateless.

  • Transaction Management: Use @Transactional on service methods. In Kotlin, this can be applied to class or function level.

Data Layer (Repositories)

  • JPA Entities: Define entities as classes. Remember they must be open. It's highly recommended to use the kotlin-jpa compiler plugin to handle this automatically.

  • Null Safety: Leverage Kotlin's null-safety (?) to clearly define which entity fields are optional or required at the type level.

  • Spring Data JPA: Use Spring Data JPA repositories by extending JpaRepository or CrudRepository.

  • Coroutines: For reactive applications, leverage Spring Boot's support for Kotlin Coroutines in the data layer.

Logging

  • Companion Object Logger: The idiomatic way to declare a logger is in a companion object.
Copy & paste — that's it
companion object {
 private val logger = LoggerFactory.getLogger(MyClass::class.java)
}
  • Parameterized Logging: Use parameterized messages (logger.info("Processing user {}...", userId)) for performance and clarity.

Testing

  • JUnit 5: JUnit 5 is the default and works seamlessly with Kotlin.

  • Idiomatic Testing Libraries: For more fluent and idiomatic tests, consider using Kotest for assertions and MockK for mocking. They are designed for Kotlin and offer a more expressive syntax.

  • Test Slices: Use test slice annotations like @WebMvcTest or @DataJpaTest to test specific parts of the application.

  • Testcontainers: Use Testcontainers for reliable integration tests with real databases, message brokers, etc.

Coroutines & Asynchronous Programming

  • suspend functions: For non-blocking asynchronous code, use suspend functions in your controllers and services. Spring Boot has excellent support for coroutines.

  • Structured Concurrency: Use coroutineScope or supervisorScope to manage the lifecycle of coroutines.