├── .editorconfig ├── .gitignore ├── README.md ├── api-server ├── build.gradle.kts └── src │ ├── main │ ├── kotlin │ │ └── com │ │ │ └── kshired │ │ │ └── boilerplate │ │ │ └── apiserver │ │ │ ├── ApiServerApplication.kt │ │ │ ├── controller │ │ │ └── v1 │ │ │ │ ├── example │ │ │ │ ├── ExampleController.kt │ │ │ │ └── response │ │ │ │ │ └── CatFactResponse.kt │ │ │ │ └── user │ │ │ │ ├── UserController.kt │ │ │ │ ├── request │ │ │ │ └── UserCreateRequest.kt │ │ │ │ └── response │ │ │ │ └── UserResponse.kt │ │ │ └── support │ │ │ └── error │ │ │ └── ApiExceptionHandler.kt │ └── resources │ │ └── application.yml │ └── test │ └── kotlin │ └── com │ └── kshired │ └── boilerplate │ └── apiserver │ └── ApiServerApplicationTests.kt ├── build.gradle.kts ├── clients └── client-example │ ├── build.gradle.kts │ └── src │ └── main │ ├── kotlin │ └── com │ │ └── kshired │ │ └── boilerplate │ │ └── clients │ │ └── client │ │ └── example │ │ ├── ExampleApi.kt │ │ ├── ExampleApiConfig.kt │ │ ├── ExampleClient.kt │ │ └── response │ │ └── ExampleResponse.kt │ └── resources │ └── client-example.yml ├── common ├── enum │ └── build.gradle.kts ├── error │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── kshired │ │ └── boilerplate │ │ └── common │ │ └── error │ │ ├── BadRequestException.kt │ │ └── InternalServerException.kt └── util │ ├── build.gradle.kts │ └── src │ └── main │ └── kotlin │ └── com │ └── kshired │ └── boilerplate │ └── common │ └── util │ └── response │ ├── ApiResponse.kt │ ├── CursorPageResponse.kt │ └── PageResponse.kt ├── domain ├── build.gradle.kts └── src │ └── main │ └── kotlin │ └── com │ └── kshired │ └── boilerplate │ └── domain │ └── user │ ├── User.kt │ ├── UserCreator.kt │ ├── UserReader.kt │ ├── UserRepository.kt │ └── UserService.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── init.sh ├── settings.gradle.kts ├── storage └── rdb │ ├── build.gradle.kts │ └── src │ └── main │ ├── kotlin │ └── com │ │ └── kshired │ │ └── boilerplate │ │ └── storage │ │ └── rdb │ │ ├── BaseEntity.kt │ │ ├── config │ │ ├── MainDataSourceConfig.kt │ │ └── MainJpaConfig.kt │ │ └── user │ │ ├── UserEntity.kt │ │ ├── UserJpaRepository.kt │ │ └── UserRepositoryJpaImpl.kt │ └── resources │ └── storage-rdb.yml └── support └── logging ├── build.gradle.kts └── src └── main └── resources ├── logback └── logback-local.xml └── logging.yml /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | max_line_length = 120 11 | tab_width = 4 12 | 13 | [*.{kt,kts}] 14 | disabled_rules=import-ordering 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | 39 | ### Mac ### 40 | .DS_Store 41 | ./**/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin + Spring 멀티 모듈 프로젝트 2 | 3 | ## 사용법 4 | - init.sh 을 실행하여, group, project 이름을 입력한다. 5 | 6 | ## 환경 7 | - Spring Boot 3.2.2 8 | - Kotlin 1.9.22 9 | - JVM 21 10 | 11 | ### Reference 12 | - https://github.com/team-dodn/live-code-show 13 | -------------------------------------------------------------------------------- /api-server/build.gradle.kts: -------------------------------------------------------------------------------- 1 | tasks.getByName("bootJar") { 2 | enabled = true 3 | } 4 | 5 | tasks.getByName("jar") { 6 | enabled = false 7 | } 8 | 9 | dependencies { 10 | implementation(project(":clients:client-example")) 11 | implementation(project(":common:enum")) 12 | implementation(project(":common:util")) 13 | implementation(project(":common:error")) 14 | implementation(project(":domain")) 15 | implementation(project(":support:logging")) 16 | implementation(project(":storage:rdb")) 17 | implementation("org.springframework.boot:spring-boot-starter-web") 18 | } -------------------------------------------------------------------------------- /api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/ApiServerApplication.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.runApplication 5 | import org.springframework.context.annotation.ComponentScan 6 | 7 | @ComponentScan(basePackages = ["com.kshired.boilerplate"]) 8 | @SpringBootApplication 9 | class ApiServerApplication 10 | 11 | fun main(args: Array) { 12 | runApplication(*args) 13 | } 14 | -------------------------------------------------------------------------------- /api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/controller/v1/example/ExampleController.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver.controller.v1.example 2 | 3 | import com.kshired.boilerplate.apiserver.controller.v1.example.response.CatFactResponse 4 | import com.kshired.boilerplate.clients.client.example.ExampleClient 5 | import com.kshired.boilerplate.common.util.response.ApiResponse 6 | import org.springframework.web.bind.annotation.GetMapping 7 | import org.springframework.web.bind.annotation.RequestMapping 8 | import org.springframework.web.bind.annotation.RestController 9 | 10 | @RestController 11 | @RequestMapping("/api/v1/example") 12 | class ExampleController( 13 | // (예시용) 보통 client를 controller에서 직접 사용하지는 않습니다. service 혹은 구현 계층에서 사용하는게 일반적입니다. 14 | private val exampleClient: ExampleClient 15 | ) { 16 | @GetMapping("/cat/fact") 17 | fun getCatFact(): ApiResponse { 18 | return ApiResponse.success(CatFactResponse(exampleClient.getCatFacts())) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/controller/v1/example/response/CatFactResponse.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver.controller.v1.example.response 2 | 3 | data class CatFactResponse( 4 | val fact: String 5 | ) 6 | -------------------------------------------------------------------------------- /api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/controller/v1/user/UserController.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver.controller.v1.user 2 | 3 | import com.kshired.boilerplate.apiserver.controller.v1.user.request.UserCreateRequest 4 | import com.kshired.boilerplate.apiserver.controller.v1.user.response.UserResponse 5 | import com.kshired.boilerplate.domain.user.UserService 6 | import com.kshired.boilerplate.common.util.response.ApiResponse 7 | import org.springframework.web.bind.annotation.GetMapping 8 | import org.springframework.web.bind.annotation.PathVariable 9 | import org.springframework.web.bind.annotation.PostMapping 10 | import org.springframework.web.bind.annotation.RequestBody 11 | import org.springframework.web.bind.annotation.RequestMapping 12 | import org.springframework.web.bind.annotation.RestController 13 | 14 | @RestController 15 | @RequestMapping("/api/v1/users") 16 | class UserController( 17 | private val userService: UserService 18 | ) { 19 | @GetMapping("/{id}") 20 | fun findUserById( 21 | @PathVariable("id") id: Long 22 | ): ApiResponse { 23 | val findUser = userService.findById(id) 24 | return ApiResponse.success(UserResponse.fromDomain(findUser)) 25 | } 26 | 27 | @PostMapping 28 | fun createUser( 29 | @RequestBody userCreateRequest: UserCreateRequest 30 | ): ApiResponse { 31 | userService.createUser(userCreateRequest.toDomain()) 32 | return ApiResponse.success(true) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/controller/v1/user/request/UserCreateRequest.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver.controller.v1.user.request 2 | 3 | import com.kshired.boilerplate.domain.user.User 4 | 5 | data class UserCreateRequest( 6 | val username: String, 7 | val email: String 8 | ) { 9 | fun toDomain(): User { 10 | return User( 11 | username = username, 12 | email = email 13 | ) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/controller/v1/user/response/UserResponse.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver.controller.v1.user.response 2 | 3 | import com.kshired.boilerplate.domain.user.User 4 | 5 | data class UserResponse( 6 | val id: Long, 7 | val username: String, 8 | val email: String 9 | ) { 10 | companion object { 11 | fun fromDomain(domain: User): UserResponse { 12 | return UserResponse( 13 | id = domain.id, 14 | username = domain.username, 15 | email = domain.email 16 | ) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /api-server/src/main/kotlin/com/kshired/boilerplate/apiserver/support/error/ApiExceptionHandler.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver.support.error 2 | 3 | import com.kshired.boilerplate.common.error.BadRequestException 4 | import com.kshired.boilerplate.common.error.InternalServerException 5 | import com.kshired.boilerplate.common.util.response.ApiResponse 6 | import org.slf4j.LoggerFactory 7 | import org.springframework.web.bind.annotation.ExceptionHandler 8 | import org.springframework.web.bind.annotation.RestControllerAdvice 9 | 10 | @RestControllerAdvice 11 | class ApiExceptionHandler { 12 | private val logger = LoggerFactory.getLogger(javaClass) 13 | 14 | @ExceptionHandler(BadRequestException::class) 15 | fun handleBadRequestException(e: BadRequestException): ApiResponse { 16 | logger.warn(e.message, e) 17 | return ApiResponse.fail(e.message) 18 | } 19 | 20 | @ExceptionHandler(InternalServerException::class) 21 | fun handleInternalServerException(e: InternalServerException): ApiResponse { 22 | logger.error(e.message, e) 23 | return ApiResponse.error(e.message) 24 | } 25 | 26 | @ExceptionHandler(Exception::class) 27 | fun handleUnknownException(e: Exception): ApiResponse { 28 | logger.error(e.message, e) 29 | return ApiResponse.error("서버에서 알 수 없는 에러가 발생했습니다.") 30 | } 31 | } -------------------------------------------------------------------------------- /api-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring.application.name: api-server 2 | spring.profiles.active: local 3 | 4 | spring: 5 | config: 6 | import: 7 | - logging.yml 8 | - storage-rdb.yml 9 | - client-example.yml 10 | --- 11 | spring.config.activate.on-profile: local 12 | 13 | 14 | --- 15 | spring.config.activate.on-profile: local-dev 16 | 17 | 18 | --- 19 | spring.config.activate.on-profile: dev 20 | 21 | 22 | --- 23 | spring.config.activate.on-profile: staging 24 | 25 | 26 | --- 27 | spring.config.activate.on-profile: live -------------------------------------------------------------------------------- /api-server/src/test/kotlin/com/kshired/boilerplate/apiserver/ApiServerApplicationTests.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.springframework.boot.test.context.SpringBootTest 5 | 6 | @SpringBootTest 7 | class ApiServerApplicationTests { 8 | 9 | @Test 10 | fun contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | plugins { 4 | kotlin("jvm") 5 | kotlin("kapt") 6 | kotlin("plugin.spring") apply false 7 | kotlin("plugin.jpa") apply false 8 | id("org.springframework.boot") apply false 9 | id("io.spring.dependency-management") 10 | id("org.jlleitschuh.gradle.ktlint") 11 | } 12 | 13 | val javaVersion: String by project 14 | val projectGroup: String by project 15 | val applicationVersion: String by project 16 | java.sourceCompatibility = JavaVersion.valueOf("VERSION_$javaVersion") 17 | 18 | allprojects { 19 | group = projectGroup 20 | version = applicationVersion 21 | 22 | repositories { 23 | mavenCentral() 24 | maven(url = "https://repo.spring.io/milestone") 25 | } 26 | } 27 | 28 | subprojects { 29 | apply(plugin = "org.jetbrains.kotlin.jvm") 30 | apply(plugin = "org.jetbrains.kotlin.kapt") 31 | apply(plugin = "org.jetbrains.kotlin.plugin.spring") 32 | apply(plugin = "org.jetbrains.kotlin.plugin.jpa") 33 | apply(plugin = "org.jetbrains.kotlin.plugin.noarg") 34 | apply(plugin = "org.springframework.boot") 35 | apply(plugin = "io.spring.dependency-management") 36 | 37 | dependencyManagement { 38 | val springCloudDependenciesVersion: String by project 39 | imports { 40 | mavenBom("org.springframework.cloud:spring-cloud-dependencies:$springCloudDependenciesVersion") 41 | } 42 | } 43 | 44 | dependencies { 45 | implementation("com.fasterxml.jackson.module:jackson-module-kotlin") 46 | implementation("org.jetbrains.kotlin:kotlin-reflect") 47 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 48 | testImplementation("org.springframework.boot:spring-boot-starter-test") 49 | testImplementation("io.kotest:kotest-runner-junit5:5.4.2") 50 | testImplementation("io.kotest:kotest-assertions-core:5.4.2") 51 | testImplementation("io.kotest.extensions:kotest-extensions-spring:1.1.2") 52 | annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") 53 | kapt("org.springframework.boot:spring-boot-configuration-processor") 54 | } 55 | 56 | tasks.getByName("bootJar") { 57 | enabled = false 58 | } 59 | 60 | tasks.getByName("jar") { 61 | enabled = true 62 | } 63 | 64 | tasks.withType { 65 | kotlinOptions { 66 | freeCompilerArgs = listOf("-Xjsr305=strict") 67 | jvmTarget = javaVersion 68 | } 69 | } 70 | 71 | tasks.withType { 72 | useJUnitPlatform() 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /clients/client-example/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation(project(":common:enum")) 3 | implementation(project(":common:util")) 4 | implementation("org.springframework.cloud:spring-cloud-starter-openfeign") 5 | } -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/com/kshired/boilerplate/clients/client/example/ExampleApi.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.clients.client.example 2 | 3 | import com.kshired.boilerplate.clients.client.example.response.ExampleResponse 4 | import org.springframework.cloud.openfeign.FeignClient 5 | import org.springframework.web.bind.annotation.GetMapping 6 | 7 | @FeignClient(name = "example", url = "https://catfact.ninja") 8 | interface ExampleApi { 9 | @GetMapping("/fact") 10 | fun getFact(): ExampleResponse 11 | } 12 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/com/kshired/boilerplate/clients/client/example/ExampleApiConfig.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.clients.client.example 2 | 3 | import org.springframework.cloud.openfeign.EnableFeignClients 4 | import org.springframework.context.annotation.Configuration 5 | 6 | @EnableFeignClients(basePackages = ["com.kshired.boilerplate.clients.client.example"]) 7 | @Configuration 8 | internal class ExampleApiConfig 9 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/com/kshired/boilerplate/clients/client/example/ExampleClient.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.clients.client.example 2 | 3 | import org.springframework.stereotype.Component 4 | 5 | @Component 6 | class ExampleClient( 7 | private val exampleApi: ExampleApi 8 | ) { 9 | fun getCatFacts(): String { 10 | return exampleApi.getFact().fact 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/com/kshired/boilerplate/clients/client/example/response/ExampleResponse.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.clients.client.example.response 2 | 3 | data class ExampleResponse( 4 | val fact: String, 5 | val length: Int 6 | ) 7 | -------------------------------------------------------------------------------- /clients/client-example/src/main/resources/client-example.yml: -------------------------------------------------------------------------------- 1 | feign: 2 | client: 3 | config: 4 | example: 5 | connectTimeout: 2000 6 | readTimeout: 5000 7 | loggerLevel: full 8 | compression: 9 | response: 10 | enabled: false 11 | useGzipDecoder: false 12 | httpclient: 13 | maxConnections: 2000 14 | maxConnectionsPerRoute: 2000 15 | 16 | --- 17 | spring.config.activate.on-profile: local 18 | 19 | 20 | --- 21 | spring.config.activate.on-profile: local-dev 22 | 23 | 24 | --- 25 | spring.config.activate.on-profile: dev 26 | 27 | 28 | --- 29 | spring.config.activate.on-profile: staging 30 | 31 | 32 | --- 33 | spring.config.activate.on-profile: live -------------------------------------------------------------------------------- /common/enum/build.gradle.kts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kshired/kotlin-spring-multi-module-example/ed3a79416fe7f5e9f970ccf87e990ce8c451f6b4/common/enum/build.gradle.kts -------------------------------------------------------------------------------- /common/error/build.gradle.kts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kshired/kotlin-spring-multi-module-example/ed3a79416fe7f5e9f970ccf87e990ce8c451f6b4/common/error/build.gradle.kts -------------------------------------------------------------------------------- /common/error/src/main/kotlin/com/kshired/boilerplate/common/error/BadRequestException.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.common.error 2 | 3 | data class BadRequestException( 4 | override val message: String 5 | ) : Exception(message) 6 | -------------------------------------------------------------------------------- /common/error/src/main/kotlin/com/kshired/boilerplate/common/error/InternalServerException.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.common.error 2 | 3 | class InternalServerException( 4 | override val message: String 5 | ) : Exception(message) 6 | -------------------------------------------------------------------------------- /common/util/build.gradle.kts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kshired/kotlin-spring-multi-module-example/ed3a79416fe7f5e9f970ccf87e990ce8c451f6b4/common/util/build.gradle.kts -------------------------------------------------------------------------------- /common/util/src/main/kotlin/com/kshired/boilerplate/common/util/response/ApiResponse.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.common.util.response 2 | 3 | data class ApiResponse private constructor( 4 | val data: T?, 5 | val message: String?, 6 | val status: String 7 | ) { 8 | companion object { 9 | fun success(data: T): ApiResponse { 10 | return ApiResponse(data, null, "success") 11 | } 12 | 13 | fun fail(message: String? = null): ApiResponse { 14 | return ApiResponse(null, message, "fail") 15 | } 16 | 17 | fun error(message: String): ApiResponse { 18 | return ApiResponse(null, message, "error") 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /common/util/src/main/kotlin/com/kshired/boilerplate/common/util/response/CursorPageResponse.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.apiserver.support.response 2 | 3 | data class CursorPageResponse( 4 | val offset: Long, 5 | val content: List, 6 | val totalElements: Long, 7 | val hasNext: Boolean, 8 | val contentSize: Int 9 | ) -------------------------------------------------------------------------------- /common/util/src/main/kotlin/com/kshired/boilerplate/common/util/response/PageResponse.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.common.util.response 2 | 3 | data class PageResponse( 4 | val content: List, 5 | val totalElements: Long, 6 | val totalPages: Int, 7 | val currentPage: Int, 8 | val size: Int 9 | ) 10 | -------------------------------------------------------------------------------- /domain/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation(project(":common:enum")) 3 | implementation(project(":common:util")) 4 | implementation(project(":common:error")) 5 | implementation("org.springframework:spring-context") 6 | } -------------------------------------------------------------------------------- /domain/src/main/kotlin/com/kshired/boilerplate/domain/user/User.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.domain.user 2 | 3 | data class User( 4 | val id: Long = 0, 5 | val username: String, 6 | val email: String 7 | ) 8 | -------------------------------------------------------------------------------- /domain/src/main/kotlin/com/kshired/boilerplate/domain/user/UserCreator.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.domain.user 2 | 3 | import org.springframework.stereotype.Component 4 | 5 | @Component 6 | class UserCreator( 7 | private val userRepository: UserRepository 8 | ) { 9 | fun createUser(user: User) { 10 | userRepository.create(user) 11 | } 12 | } -------------------------------------------------------------------------------- /domain/src/main/kotlin/com/kshired/boilerplate/domain/user/UserReader.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.domain.user 2 | 3 | import org.springframework.stereotype.Component 4 | 5 | @Component 6 | class UserReader( 7 | private val userRepository: UserRepository 8 | ) { 9 | fun findByIdOrNull(id: Long): User? { 10 | return userRepository.findByIdOrNull(id) 11 | } 12 | } -------------------------------------------------------------------------------- /domain/src/main/kotlin/com/kshired/boilerplate/domain/user/UserRepository.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.domain.user 2 | 3 | interface UserRepository { 4 | fun findByIdOrNull(id: Long): User? 5 | 6 | fun create(user: User) 7 | } -------------------------------------------------------------------------------- /domain/src/main/kotlin/com/kshired/boilerplate/domain/user/UserService.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.domain.user 2 | 3 | import com.kshired.boilerplate.common.error.BadRequestException 4 | import org.springframework.stereotype.Service 5 | 6 | @Service 7 | class UserService( 8 | private val userReader: UserReader, 9 | private val userCreator: UserCreator 10 | ) { 11 | fun findById(id: Long): User { 12 | return userReader.findByIdOrNull(id) 13 | ?: throw BadRequestException("$id 를 가진 user를 찾을 수 없습니다.") 14 | } 15 | 16 | fun createUser(user: User) { 17 | userCreator.createUser(user) 18 | } 19 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ### Application version ### 2 | applicationVersion=0.0.1 3 | 4 | ### Project configs ### 5 | projectGroup=com.kshired 6 | 7 | ### Project dependency versions ### 8 | kotlinVersion=1.9.22 9 | javaVersion=21 10 | 11 | ### Spring dependency versions ### 12 | springBootVersion=3.2.2 13 | springDependencyManagementVersion=1.1.4 14 | springCloudDependenciesVersion=2023.0.0 15 | 16 | ## Kotlin style ### 17 | kotlin.code.style=official 18 | ktlintVersion=12.1.0 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kshired/kotlin-spring-multi-module-example/ed3a79416fe7f5e9f970ccf87e990ce8c451f6b4/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # input 4 | read -p "Input project groups ( ex \"com.kshired\" ): " groups 5 | read -p "Input project name ( ex \"example-project\" ): " projectName 6 | 7 | # kebab case to dot case 8 | dotCaseProjectName=${projectName//-/.} 9 | 10 | # change all files package name 11 | echo "Change all files package name from \"com.kshired.boilerplate\" to \"${groups}.${dotCaseProjectName}\"" 12 | regexForChangePackage="s/com.kshired.boilerplate/${groups}.${dotCaseProjectName}/g" 13 | find . -name "*.kt" -exec perl -pi -e ${regexForChangePackage} {} \; 2>/dev/null 14 | 15 | # change project name 16 | echo "Change project name from \"example-project\" to \"$projectName\"" 17 | regexForChangeProjectName="s/example-project/${projectName}/g" 18 | find . -name "*.kts" -exec perl -pi -e ${regexForChangeProjectName} {} \; 2>/dev/null 19 | 20 | # change project groups 21 | echo "Change project groups from \"com.kshired\" to \"$groups\"" 22 | regexForChangeProjectGroup="s/com.kshired/${groups}/g" 23 | find . -name "*.properties" -exec perl -pi -e ${regexForChangeProjectGroup} {} \; 2>/dev/null 24 | 25 | # set sub directories 26 | subDirectories=${groups//./\/}/${dotCaseProjectName//./\/} 27 | 28 | # create all sub directories 29 | echo "Create all directories \"${groups}.${dotCaseProjectName}\"" 30 | createSubDirectoriesCommand="mkdir -p \$1/${subDirectories}" 31 | find . -type d -name "kotlin" -exec bash -c "$createSubDirectoriesCommand" - '{}' \; 2>/dev/null 32 | 33 | # move all directories and files 34 | echo "Move directories from \"com.kshired.boilerplate\" to \"${groups}.${dotCaseProjectName}\"" 35 | moveDirectoriesCommand="mv -v \$1/com/kshired/boilerplate/* \$1/${subDirectories} && rm -rf \$1/com/kshired/boilerplate" 36 | find . -type d -name "kotlin" -exec bash -c "$moveDirectoriesCommand" - '{}' \; 2>/dev/null 37 | 38 | # cleaning all useless directories 39 | find . -name ".DS_Store" -type f -delete 2>/dev/null 40 | find . -type d -name "kshired" -empty -exec rmdir {} \; 2>/dev/null 41 | find . -type d -name "com" -empty -exec rmdir {} \; 2>/dev/null -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "example-project" 2 | 3 | include( 4 | "api-server", 5 | "common:enum", 6 | "common:util", 7 | "common:error", 8 | "clients:client-example", 9 | "domain", 10 | "storage:rdb", 11 | "support:logging", 12 | ) 13 | 14 | pluginManagement { 15 | val kotlinVersion: String by settings 16 | val springBootVersion: String by settings 17 | val springDependencyManagementVersion: String by settings 18 | val ktlintVersion: String by settings 19 | 20 | resolutionStrategy { 21 | eachPlugin { 22 | when (requested.id.id) { 23 | "org.jetbrains.kotlin.jvm" -> useVersion(kotlinVersion) 24 | "org.jetbrains.kotlin.plugin.spring" -> useVersion(kotlinVersion) 25 | "org.jetbrains.kotlin.plugin.jpa" -> useVersion(kotlinVersion) 26 | "org.jetbrains.kotlin.kapt" -> useVersion(kotlinVersion) 27 | "org.springframework.boot" -> useVersion(springBootVersion) 28 | "io.spring.dependency-management" -> useVersion(springDependencyManagementVersion) 29 | "org.jlleitschuh.gradle.ktlint" -> useVersion(ktlintVersion) 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /storage/rdb/build.gradle.kts: -------------------------------------------------------------------------------- 1 | allOpen { 2 | annotation("jakarta.persistence.Entity") 3 | annotation("jakarta.persistence.MappedSuperclass") 4 | annotation("jakarta.persistence.Embeddable") 5 | } 6 | 7 | dependencies { 8 | implementation(project(":common:enum")) 9 | implementation(project(":common:util")) 10 | compileOnly(project(":domain")) 11 | implementation("org.springframework.boot:spring-boot-starter-data-jpa") 12 | runtimeOnly("com.h2database:h2") 13 | } -------------------------------------------------------------------------------- /storage/rdb/src/main/kotlin/com/kshired/boilerplate/storage/rdb/BaseEntity.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.storage.rdb 2 | 3 | import jakarta.persistence.MappedSuperclass 4 | import org.hibernate.annotations.CreationTimestamp 5 | import org.hibernate.annotations.UpdateTimestamp 6 | import java.time.ZonedDateTime 7 | 8 | @MappedSuperclass 9 | internal abstract class BaseEntity( 10 | @CreationTimestamp 11 | val createdAt: ZonedDateTime? = null, 12 | 13 | @UpdateTimestamp 14 | var updatedAt: ZonedDateTime? = null, 15 | ) 16 | -------------------------------------------------------------------------------- /storage/rdb/src/main/kotlin/com/kshired/boilerplate/storage/rdb/config/MainDataSourceConfig.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.storage.rdb.config 2 | 3 | import com.zaxxer.hikari.HikariConfig 4 | import com.zaxxer.hikari.HikariDataSource 5 | import org.springframework.beans.factory.annotation.Qualifier 6 | import org.springframework.boot.context.properties.ConfigurationProperties 7 | import org.springframework.context.annotation.Bean 8 | import org.springframework.context.annotation.Configuration 9 | 10 | @Configuration 11 | internal class MainDataSourceConfig { 12 | @Bean 13 | @ConfigurationProperties(prefix = "rdb.datasource.main") 14 | fun mainHikariConfig(): HikariConfig { 15 | return HikariConfig() 16 | } 17 | 18 | @Bean 19 | fun mainDataSource(@Qualifier("mainHikariConfig") config: HikariConfig): HikariDataSource { 20 | return HikariDataSource(config) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /storage/rdb/src/main/kotlin/com/kshired/boilerplate/storage/rdb/config/MainJpaConfig.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.storage.rdb.config 2 | 3 | import org.springframework.boot.autoconfigure.domain.EntityScan 4 | import org.springframework.context.annotation.Configuration 5 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories 6 | import org.springframework.transaction.annotation.EnableTransactionManagement 7 | 8 | @Configuration 9 | @EnableTransactionManagement 10 | @EntityScan(basePackages = ["com.kshired.boilerplate.storage.rdb"]) 11 | @EnableJpaRepositories(basePackages = ["com.kshired.boilerplate.storage.rdb"]) 12 | internal class MainJpaConfig 13 | -------------------------------------------------------------------------------- /storage/rdb/src/main/kotlin/com/kshired/boilerplate/storage/rdb/user/UserEntity.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.storage.rdb.user 2 | 3 | import com.kshired.boilerplate.domain.user.User 4 | import com.kshired.boilerplate.storage.rdb.BaseEntity 5 | import jakarta.persistence.Column 6 | import jakarta.persistence.Entity 7 | import jakarta.persistence.GeneratedValue 8 | import jakarta.persistence.GenerationType 9 | import jakarta.persistence.Id 10 | import jakarta.persistence.Table 11 | 12 | @Entity 13 | @Table(name = "users") 14 | internal class UserEntity( 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | val id: Long = 0, 18 | 19 | @Column(name = "username") 20 | val username: String, 21 | 22 | @Column(name = "email") 23 | val email: String 24 | ) : BaseEntity() { 25 | companion object { 26 | fun fromDomain(domain: User) : UserEntity { 27 | return UserEntity( 28 | id = domain.id, 29 | username = domain.username, 30 | email = domain.email 31 | ) 32 | } 33 | } 34 | 35 | fun toDomain(): User { 36 | return User( 37 | id = id, 38 | username = username, 39 | email = email 40 | ) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /storage/rdb/src/main/kotlin/com/kshired/boilerplate/storage/rdb/user/UserJpaRepository.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.storage.rdb.user 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository 4 | import org.springframework.stereotype.Repository 5 | 6 | @Repository 7 | internal interface UserJpaRepository : JpaRepository 8 | -------------------------------------------------------------------------------- /storage/rdb/src/main/kotlin/com/kshired/boilerplate/storage/rdb/user/UserRepositoryJpaImpl.kt: -------------------------------------------------------------------------------- 1 | package com.kshired.boilerplate.storage.rdb.user 2 | 3 | import com.kshired.boilerplate.domain.user.User 4 | import com.kshired.boilerplate.domain.user.UserRepository 5 | import org.springframework.data.repository.findByIdOrNull 6 | import org.springframework.stereotype.Repository 7 | 8 | @Repository 9 | internal class UserRepositoryJpaImpl( 10 | private val userJpaRepository: UserJpaRepository 11 | ) : UserRepository { 12 | override fun findByIdOrNull(id: Long): User? { 13 | return userJpaRepository.findByIdOrNull(id)?.toDomain() 14 | } 15 | 16 | override fun create(user: User) { 17 | userJpaRepository.save(UserEntity.fromDomain(user)) 18 | } 19 | } -------------------------------------------------------------------------------- /storage/rdb/src/main/resources/storage-rdb.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | open-in-view: false 4 | hibernate: 5 | ddl-auto: none 6 | properties: 7 | hibernate: 8 | default_batch_fetch_size: 100 9 | 10 | --- 11 | spring.config.activate.on-profile: local 12 | 13 | spring: 14 | jpa: 15 | hibernate: 16 | ddl-auto: create 17 | properties: 18 | hibernate: 19 | format_sql: true 20 | show_sql: true 21 | h2: 22 | console: 23 | enabled: true 24 | 25 | rdb: 26 | datasource: 27 | main: 28 | driver-class-name: org.h2.Driver 29 | jdbc-url: jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 30 | username: sa 31 | pool-name: main-db-pool 32 | data-source-properties: 33 | rewriteBatchedStatements: true 34 | 35 | --- 36 | spring.config.activate.on-profile: local-dev 37 | 38 | 39 | --- 40 | spring.config.activate.on-profile: dev 41 | 42 | 43 | --- 44 | spring.config.activate.on-profile: staging 45 | 46 | 47 | --- 48 | spring.config.activate.on-profile: live 49 | -------------------------------------------------------------------------------- /support/logging/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation("io.micrometer:micrometer-tracing-bridge-brave") 3 | } 4 | -------------------------------------------------------------------------------- /support/logging/src/main/resources/logback/logback-local.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %clr(%d{HH:mm:ss.SSS}){faint}|%clr(${level:-%5p})|%32X{traceId:-},%16X{spanId:-}|%clr(%-40.40logger{39}){cyan}%clr(|){faint}%m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} 8 | utf8 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /support/logging/src/main/resources/logging.yml: -------------------------------------------------------------------------------- 1 | logging.config: classpath:logback/logback-${spring.profiles.active}.xml 2 | --------------------------------------------------------------------------------