├── .editorconfig ├── .gitattributes ├── .githooks └── pre-commit ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENCE.md ├── README.md ├── build.gradle.kts ├── clients └── client-example │ ├── build.gradle.kts │ └── src │ ├── main │ ├── kotlin │ │ └── io │ │ │ └── dodn │ │ │ └── springboot │ │ │ └── client │ │ │ └── example │ │ │ ├── ExampleApi.kt │ │ │ ├── ExampleClient.kt │ │ │ ├── ExampleConfig.kt │ │ │ ├── ExampleRequestDto.kt │ │ │ ├── ExampleResponseDto.kt │ │ │ └── model │ │ │ └── ExampleClientResult.kt │ └── resources │ │ └── client-example.yml │ └── test │ ├── kotlin │ └── io │ │ └── dodn │ │ └── springboot │ │ └── client │ │ ├── ClientExampleContextTest.kt │ │ ├── ClientExampleTestApplication.kt │ │ └── example │ │ └── ExampleClientTest.kt │ └── resources │ └── application.yml ├── core ├── core-api │ ├── build.gradle.kts │ └── src │ │ ├── docs │ │ └── asciidoc │ │ │ └── index.adoc │ │ ├── main │ │ ├── kotlin │ │ │ └── io │ │ │ │ └── dodn │ │ │ │ └── springboot │ │ │ │ ├── CoreApiApplication.kt │ │ │ │ └── core │ │ │ │ ├── api │ │ │ │ ├── config │ │ │ │ │ ├── AsyncConfig.kt │ │ │ │ │ └── AsyncExceptionHandler.kt │ │ │ │ └── controller │ │ │ │ │ ├── ApiControllerAdvice.kt │ │ │ │ │ ├── HealthController.kt │ │ │ │ │ └── v1 │ │ │ │ │ ├── ExampleController.kt │ │ │ │ │ ├── request │ │ │ │ │ └── ExampleRequestDto.kt │ │ │ │ │ └── response │ │ │ │ │ └── ExampleResponseDto.kt │ │ │ │ ├── domain │ │ │ │ ├── ExampleData.kt │ │ │ │ ├── ExampleResult.kt │ │ │ │ └── ExampleService.kt │ │ │ │ └── support │ │ │ │ ├── error │ │ │ │ ├── CoreException.kt │ │ │ │ ├── ErrorCode.kt │ │ │ │ ├── ErrorMessage.kt │ │ │ │ └── ErrorType.kt │ │ │ │ └── response │ │ │ │ ├── ApiResponse.kt │ │ │ │ └── ResultType.kt │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── kotlin │ │ └── io │ │ └── dodn │ │ └── springboot │ │ ├── ContextTest.kt │ │ ├── CoreApiApplicationTest.kt │ │ ├── DevelopTest.kt │ │ └── core │ │ └── api │ │ └── controller │ │ └── v1 │ │ └── ExampleControllerTest.kt └── core-enum │ ├── build.gradle.kts │ └── src │ └── main │ └── kotlin │ └── io │ └── dodn │ └── springboot │ └── core │ └── enums │ └── ExampleEnum.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts ├── storage └── db-core │ ├── build.gradle.kts │ └── src │ ├── main │ ├── kotlin │ │ └── io │ │ │ └── dodn │ │ │ └── springboot │ │ │ └── storage │ │ │ └── db │ │ │ └── core │ │ │ ├── BaseEntity.kt │ │ │ ├── ExampleEntity.kt │ │ │ ├── ExampleRepository.kt │ │ │ └── config │ │ │ ├── CoreDataSourceConfig.kt │ │ │ └── CoreJpaConfig.kt │ └── resources │ │ └── db-core.yml │ └── test │ ├── kotlin │ └── io │ │ └── dodn │ │ └── springboot │ │ └── storage │ │ └── db │ │ ├── CoreDbContextTest.kt │ │ ├── CoreDbTestApplication.kt │ │ └── core │ │ └── ExampleRepositoryIT.kt │ └── resources │ └── application.yml ├── support ├── logging │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── resources │ │ ├── logback │ │ ├── logback-dev.xml │ │ ├── logback-live.xml │ │ ├── logback-local-dev.xml │ │ ├── logback-local.xml │ │ └── logback-staging.xml │ │ └── logging.yml └── monitoring │ ├── build.gradle.kts │ └── src │ └── main │ └── resources │ └── monitoring.yml └── tests └── api-docs ├── build.gradle.kts └── src └── main └── kotlin └── io └── dodn └── springboot └── test └── api ├── RestDocsTest.kt └── RestDocsUtils.kt /.editorconfig: -------------------------------------------------------------------------------- 1 | [{*.kt,*.kts}] 2 | ktlint_code_style = INTELLIJ_IDEA 3 | ij_kotlin_allow_trailing_comma = true 4 | ij_kotlin_allow_trailing_comma_on_call_site = true 5 | ij_kotlin_name_count_to_use_star_import = 2147483647 6 | ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 7 | ij_kotlin_packages_to_use_import_on_demand = unset -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | .githooks/** linguist-vendored 2 | gradlew linguist-vendored 3 | -------------------------------------------------------------------------------- /.githooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | GIT_DIR=$(git rev-parse --show-toplevel) 4 | $GIT_DIR/gradlew ktlintCheck 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Set up JDK 19 | uses: actions/setup-java@v3 20 | with: 21 | java-version: '21' 22 | distribution: 'adopt' 23 | - name: Lint 24 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 25 | with: 26 | arguments: ktlintCheck 27 | - name: Test 28 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 29 | with: 30 | arguments: test 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### IDEA ### 8 | .idea 9 | *.iws 10 | *.iml 11 | *.ipr 12 | out/ 13 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringBoot Kotlin Template 2 | 3 | [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2Fgeminikims)](https://twitter.com/geminikims) 4 | [![Youtube](https://img.shields.io/youtube/channel/views/UCDh8zEDofOcrOMAOnSVL9Tg?label=Youtube&style=social)](https://www.youtube.com/@geminikims) 5 | [![CI](https://github.com/team-dodn/spring-boot-kotlin-template/actions/workflows/ci.yml/badge.svg)](https://github.com/team-dodn/spring-boot-kotlin-template/actions/workflows/ci.yml) 6 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 7 | 8 | This is not the best structure. This is a good basic structure to use early in the project when productivity is important. 9 | 10 | Remember, as your software grows, your structure must grow too. 11 | 12 | # **Modules** 13 | 14 | ## Core 15 | Each submodule of this module is responsible for one domain service. 16 | 17 | This must make the modular structure grow with the growth of the service. 18 | 19 | ### core:core-api 20 | It is the only executable module in the project. It is structured to have domains to maximize initial development productivity. 21 | 22 | It is also responsible for providing APIs and setting up frameworks for services. 23 | 24 | ### core:core-enum 25 | 26 | This module contains enums that are used by `core-api` and must be delivered to external modules. 27 | 28 |
29 | 30 | ## Clients 31 | Submodules of this module are responsible for integrating with external systems. 32 | 33 | ### clients:clients-example 34 | This module shows an example of HTTP communication with `Spring-Cloud-Open-Feign`. 35 | 36 |
37 | 38 | ## Storage 39 | Submodules of this module are responsible for integrating with the various storages. 40 | 41 | ### storage:db-core 42 | This module shows an example of connecting to `MySql` using `Spring-Data-JPA`. 43 | 44 |
45 | 46 | ## Support 47 | Submodules of this module are responsible for additional support. 48 | 49 | ### support:logging 50 | This module supports logging of service and has a dependency added for distributed tracing support. 51 | 52 | It also includes dependencies to support `Sentry`. 53 | 54 | ### support:monitoring 55 | This module supports monitoring of services. 56 | 57 |
58 | 59 | ## Tests 60 | Submodules of this module are responsible for the convenience of writing test codes. 61 | 62 | ### tests:api-docs 63 | This module is for writing spring-rest-docs conveniently. 64 | 65 |
66 | 67 | # Dependency Management 68 | All dependency versioning is done through `gradle.properties` file. 69 | 70 | If you want to add a new dependency, put the version in `gradle.properties` and load it in `build.gradle.kts`. 71 | 72 |
73 | 74 | # Runtime Profiles 75 | 76 | ## local 77 | This profile aims to configure an environment that can be developed even if the network is disconnected. 78 | 79 | ## local-dev 80 | This profile aims configurations that allow me to connect to the DEV environment from my local machine. 81 | 82 | ## dev 83 | This profile exists for deploying Development environments. 84 | 85 | ## staging 86 | This profile exists for deploying Staging environments. 87 | 88 | ## live 89 | This profile exists for deploying Live environments. 90 | 91 |
92 | 93 | # Test Tasks & Tags 94 | 95 | ## test 96 | This is a collection of test-tasks that we want to run on `CI`. 97 | 98 | If you want to change the settings, modify the `build.gradle.kts` file. 99 | 100 | ## unitTest 101 | This is a group of tests that typically have no dependencies, are fast to run, and test a single feature. 102 | 103 | ## contextTest 104 | This is a task that runs with SpringContext and has integration tests. 105 | 106 | ## restDocsTest 107 | This is a task to create asciidoc based on spring-rest-docs. 108 | 109 | ## developTest 110 | This is a task of tests that should not be run in `CI`. 111 | 112 | This is a good tag to use if you're not good at writing tests. 113 | 114 |
115 | 116 | # Recommended Preferences 117 | 118 | ## Git Hook 119 | This setting makes run `lint` on every commit. 120 | 121 | ``` 122 | $ git config core.hookspath .githooks 123 | ``` 124 | 125 | ## IntelliJ IDEA 126 | This setting makes it easier to run the `test code` out of the box. 127 | 128 | ``` 129 | // Gradle Build and run with IntelliJ IDEA 130 | Build, Execution, Deployment > Build Tools > Gradle > Run tests using > IntelliJ IDEA 131 | ``` 132 | 133 | --- 134 | 135 | # Supported By 136 |
JetBrains Logo (Main) logo.
137 | -------------------------------------------------------------------------------- /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.asciidoctor.jvm.convert") apply false 11 | id("org.jlleitschuh.gradle.ktlint") apply false 12 | } 13 | 14 | java.sourceCompatibility = JavaVersion.valueOf("VERSION_${property("javaVersion")}") 15 | 16 | allprojects { 17 | group = "${property("projectGroup")}" 18 | version = "${property("applicationVersion")}" 19 | 20 | repositories { 21 | mavenCentral() 22 | } 23 | } 24 | 25 | subprojects { 26 | apply(plugin = "org.jetbrains.kotlin.jvm") 27 | apply(plugin = "org.jetbrains.kotlin.kapt") 28 | apply(plugin = "org.jetbrains.kotlin.plugin.spring") 29 | apply(plugin = "org.jetbrains.kotlin.plugin.jpa") 30 | apply(plugin = "org.springframework.boot") 31 | apply(plugin = "io.spring.dependency-management") 32 | apply(plugin = "org.asciidoctor.jvm.convert") 33 | apply(plugin = "org.jlleitschuh.gradle.ktlint") 34 | 35 | dependencyManagement { 36 | imports { 37 | mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudDependenciesVersion")}") 38 | } 39 | } 40 | 41 | dependencies { 42 | implementation("org.jetbrains.kotlin:kotlin-reflect") 43 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 44 | implementation("com.fasterxml.jackson.module:jackson-module-kotlin") 45 | testImplementation("org.springframework.boot:spring-boot-starter-test") 46 | testImplementation("com.ninja-squad:springmockk:${property("springMockkVersion")}") 47 | annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") 48 | kapt("org.springframework.boot:spring-boot-configuration-processor") 49 | } 50 | 51 | tasks.getByName("bootJar") { 52 | enabled = false 53 | } 54 | 55 | tasks.getByName("jar") { 56 | enabled = true 57 | } 58 | 59 | java.sourceCompatibility = JavaVersion.valueOf("VERSION_${property("javaVersion")}") 60 | tasks.withType { 61 | kotlinOptions { 62 | freeCompilerArgs = listOf("-Xjsr305=strict") 63 | jvmTarget = "${project.property("javaVersion")}" 64 | } 65 | } 66 | 67 | tasks.test { 68 | useJUnitPlatform { 69 | excludeTags("develop", "restdocs") 70 | } 71 | } 72 | 73 | tasks.register("unitTest") { 74 | group = "verification" 75 | useJUnitPlatform { 76 | excludeTags("develop", "context", "restdocs") 77 | } 78 | } 79 | 80 | tasks.register("contextTest") { 81 | group = "verification" 82 | useJUnitPlatform { 83 | includeTags("context") 84 | } 85 | } 86 | 87 | tasks.register("restDocsTest") { 88 | group = "verification" 89 | useJUnitPlatform { 90 | includeTags("restdocs") 91 | } 92 | } 93 | 94 | tasks.register("developTest") { 95 | group = "verification" 96 | useJUnitPlatform { 97 | includeTags("develop") 98 | } 99 | } 100 | 101 | tasks.getByName("asciidoctor") { 102 | dependsOn("restDocsTest") 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /clients/client-example/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation("org.springframework.cloud:spring-cloud-starter-openfeign") 3 | implementation("io.github.openfeign:feign-hc5") 4 | implementation("io.github.openfeign:feign-micrometer") 5 | } 6 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/io/dodn/springboot/client/example/ExampleApi.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example 2 | 3 | import org.springframework.cloud.openfeign.FeignClient 4 | import org.springframework.http.MediaType 5 | import org.springframework.web.bind.annotation.RequestBody 6 | import org.springframework.web.bind.annotation.RequestMapping 7 | import org.springframework.web.bind.annotation.RequestMethod 8 | 9 | @FeignClient(value = "example-api", url = "\${example.api.url}") 10 | internal interface ExampleApi { 11 | @RequestMapping( 12 | method = [RequestMethod.POST], 13 | value = ["/example/example-api"], 14 | consumes = [MediaType.APPLICATION_JSON_VALUE], 15 | ) 16 | fun example(@RequestBody request: ExampleRequestDto): ExampleResponseDto 17 | } 18 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/io/dodn/springboot/client/example/ExampleClient.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example 2 | 3 | import io.dodn.springboot.client.example.model.ExampleClientResult 4 | import org.springframework.stereotype.Component 5 | 6 | @Component 7 | class ExampleClient internal constructor( 8 | private val exampleApi: ExampleApi, 9 | ) { 10 | fun example(exampleParameter: String): ExampleClientResult { 11 | val request = ExampleRequestDto(exampleParameter) 12 | return exampleApi.example(request).toResult() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/io/dodn/springboot/client/example/ExampleConfig.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example 2 | 3 | import org.springframework.cloud.openfeign.EnableFeignClients 4 | import org.springframework.context.annotation.Configuration 5 | 6 | @EnableFeignClients 7 | @Configuration 8 | internal class ExampleConfig 9 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/io/dodn/springboot/client/example/ExampleRequestDto.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example 2 | 3 | internal data class ExampleRequestDto( 4 | val exampleRequestValue: String, 5 | ) 6 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/io/dodn/springboot/client/example/ExampleResponseDto.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example 2 | 3 | import io.dodn.springboot.client.example.model.ExampleClientResult 4 | 5 | internal data class ExampleResponseDto( 6 | val exampleResponseValue: String, 7 | ) { 8 | fun toResult(): ExampleClientResult { 9 | return ExampleClientResult(exampleResponseValue) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /clients/client-example/src/main/kotlin/io/dodn/springboot/client/example/model/ExampleClientResult.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example.model 2 | 3 | data class ExampleClientResult( 4 | val exampleResult: String, 5 | ) 6 | -------------------------------------------------------------------------------- /clients/client-example/src/main/resources/client-example.yml: -------------------------------------------------------------------------------- 1 | example: 2 | api: 3 | url: https://default.example.example 4 | 5 | spring.cloud.openfeign: 6 | client: 7 | config: 8 | example-api: 9 | connectTimeout: 2100 10 | readTimeout: 5000 11 | loggerLevel: full 12 | compression: 13 | response: 14 | enabled: false 15 | httpclient: 16 | max-connections: 2000 17 | max-connections-per-route: 500 18 | 19 | --- 20 | spring.config.activate.on-profile: local 21 | 22 | --- 23 | spring.config.activate.on-profile: 24 | - local-dev 25 | - dev 26 | 27 | --- 28 | spring.config.activate.on-profile: 29 | - staging 30 | - live 31 | 32 | example: 33 | api: 34 | url: https://live.example.example 35 | 36 | -------------------------------------------------------------------------------- /clients/client-example/src/test/kotlin/io/dodn/springboot/client/ClientExampleContextTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client 2 | 3 | import org.junit.jupiter.api.Tag 4 | import org.springframework.boot.test.context.SpringBootTest 5 | import org.springframework.test.context.ActiveProfiles 6 | import org.springframework.test.context.TestConstructor 7 | 8 | @ActiveProfiles("local") 9 | @Tag("context") 10 | @SpringBootTest 11 | @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) 12 | abstract class ClientExampleContextTest 13 | -------------------------------------------------------------------------------- /clients/client-example/src/test/kotlin/io/dodn/springboot/client/ClientExampleTestApplication.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan 5 | import org.springframework.boot.runApplication 6 | 7 | @ConfigurationPropertiesScan 8 | @SpringBootApplication 9 | class ClientExampleTestApplication 10 | 11 | fun main(args: Array) { 12 | runApplication(*args) 13 | } 14 | -------------------------------------------------------------------------------- /clients/client-example/src/test/kotlin/io/dodn/springboot/client/example/ExampleClientTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example 2 | 3 | import feign.RetryableException 4 | import io.dodn.springboot.client.ClientExampleContextTest 5 | import org.assertj.core.api.Assertions 6 | import org.junit.jupiter.api.Test 7 | 8 | class ExampleClientTest( 9 | val exampleClient: ExampleClient, 10 | ) : ClientExampleContextTest() { 11 | @Test 12 | fun shouldBeThrownExceptionWhenExample() { 13 | try { 14 | exampleClient.example("HELLO!") 15 | } catch (e: Exception) { 16 | Assertions.assertThat(e).isExactlyInstanceOf(RetryableException::class.java) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /clients/client-example/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring.application.name: client-example-test 2 | 3 | spring: 4 | config: 5 | import: 6 | - client-example.yml 7 | -------------------------------------------------------------------------------- /core/core-api/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(":core:core-enum")) 11 | implementation(project(":support:monitoring")) 12 | implementation(project(":support:logging")) 13 | implementation(project(":storage:db-core")) 14 | implementation(project(":clients:client-example")) 15 | 16 | testImplementation(project(":tests:api-docs")) 17 | 18 | implementation("org.springframework.boot:spring-boot-starter-web") 19 | } 20 | -------------------------------------------------------------------------------- /core/core-api/src/docs/asciidoc/index.adoc: -------------------------------------------------------------------------------- 1 | = API Docs 2 | :doctype: book 3 | :icons: font 4 | :source-highlighter: highlightjs 5 | :toc: left 6 | :toclevels: 3 7 | :sectlinks: 8 | :snippets: build/generated-snippets 9 | 10 | == Introduce 11 | 12 | This is the Core API documentation. 13 | 14 | == Example API 15 | 16 | === Example GET API 17 | ==== Curl Request 18 | include::{snippets}/exampleGet/curl-request.adoc[] 19 | ==== Path Parameters 20 | include::{snippets}/exampleGet/path-parameters.adoc[] 21 | ==== Query Parameters 22 | include::{snippets}/exampleGet/query-parameters.adoc[] 23 | ==== Http Response 24 | include::{snippets}/exampleGet/http-response.adoc[] 25 | ==== Response Fields 26 | include::{snippets}/exampleGet/response-fields.adoc[] 27 | 28 | ''' 29 | 30 | === Example POST API 31 | ==== Curl Request 32 | include::{snippets}/examplePost/curl-request.adoc[] 33 | ==== Request Fields 34 | include::{snippets}/examplePost/request-fields.adoc[] 35 | ==== Http Response 36 | include::{snippets}/examplePost/http-response.adoc[] 37 | ==== Response Fields 38 | include::{snippets}/examplePost/response-fields.adoc[] 39 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/CoreApiApplication.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan 5 | import org.springframework.boot.runApplication 6 | 7 | @ConfigurationPropertiesScan 8 | @SpringBootApplication 9 | class CoreApiApplication 10 | 11 | fun main(args: Array) { 12 | runApplication(*args) 13 | } 14 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/api/config/AsyncConfig.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.config 2 | 3 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler 4 | import org.springframework.context.annotation.Configuration 5 | import org.springframework.scheduling.annotation.AsyncConfigurer 6 | import org.springframework.scheduling.annotation.EnableAsync 7 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor 8 | import java.util.concurrent.Executor 9 | 10 | @Configuration 11 | @EnableAsync 12 | class AsyncConfig : AsyncConfigurer { 13 | override fun getAsyncExecutor(): Executor { 14 | val executor = ThreadPoolTaskExecutor() 15 | executor.corePoolSize = 10 16 | executor.maxPoolSize = 10 17 | executor.queueCapacity = 10000 18 | executor.setWaitForTasksToCompleteOnShutdown(true) 19 | executor.setAwaitTerminationSeconds(10) 20 | executor.initialize() 21 | return executor 22 | } 23 | 24 | override fun getAsyncUncaughtExceptionHandler(): AsyncUncaughtExceptionHandler { 25 | return AsyncExceptionHandler() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/api/config/AsyncExceptionHandler.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.config 2 | 3 | import io.dodn.springboot.core.support.error.CoreException 4 | import org.slf4j.LoggerFactory 5 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler 6 | import org.springframework.boot.logging.LogLevel 7 | import java.lang.reflect.Method 8 | 9 | class AsyncExceptionHandler : AsyncUncaughtExceptionHandler { 10 | private val log = LoggerFactory.getLogger(javaClass) 11 | 12 | override fun handleUncaughtException(e: Throwable, method: Method, vararg params: Any?) { 13 | if (e is CoreException) { 14 | when (e.errorType.logLevel) { 15 | LogLevel.ERROR -> log.error("CoreException : {}", e.message, e) 16 | LogLevel.WARN -> log.warn("CoreException : {}", e.message, e) 17 | else -> log.info("CoreException : {}", e.message, e) 18 | } 19 | } else { 20 | log.error("Exception : {}", e.message, e) 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/ApiControllerAdvice.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller 2 | 3 | import io.dodn.springboot.core.support.error.CoreException 4 | import io.dodn.springboot.core.support.error.ErrorType 5 | import io.dodn.springboot.core.support.response.ApiResponse 6 | import org.slf4j.Logger 7 | import org.slf4j.LoggerFactory 8 | import org.springframework.boot.logging.LogLevel 9 | import org.springframework.http.ResponseEntity 10 | import org.springframework.web.bind.annotation.ExceptionHandler 11 | import org.springframework.web.bind.annotation.RestControllerAdvice 12 | 13 | @RestControllerAdvice 14 | class ApiControllerAdvice { 15 | private val log: Logger = LoggerFactory.getLogger(javaClass) 16 | 17 | @ExceptionHandler(CoreException::class) 18 | fun handleCoreException(e: CoreException): ResponseEntity> { 19 | when (e.errorType.logLevel) { 20 | LogLevel.ERROR -> log.error("CoreException : {}", e.message, e) 21 | LogLevel.WARN -> log.warn("CoreException : {}", e.message, e) 22 | else -> log.info("CoreException : {}", e.message, e) 23 | } 24 | return ResponseEntity(ApiResponse.error(e.errorType, e.data), e.errorType.status) 25 | } 26 | 27 | @ExceptionHandler(Exception::class) 28 | fun handleException(e: Exception): ResponseEntity> { 29 | log.error("Exception : {}", e.message, e) 30 | return ResponseEntity(ApiResponse.error(ErrorType.DEFAULT_ERROR), ErrorType.DEFAULT_ERROR.status) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/HealthController.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller 2 | 3 | import org.springframework.http.HttpStatus 4 | import org.springframework.http.ResponseEntity 5 | import org.springframework.web.bind.annotation.GetMapping 6 | import org.springframework.web.bind.annotation.RestController 7 | 8 | @RestController 9 | class HealthController { 10 | @GetMapping("/health") 11 | fun health(): ResponseEntity<*> { 12 | return ResponseEntity.status(HttpStatus.OK).build() 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/v1/ExampleController.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller.v1 2 | 3 | import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto 4 | import io.dodn.springboot.core.api.controller.v1.response.ExampleResponseDto 5 | import io.dodn.springboot.core.domain.ExampleData 6 | import io.dodn.springboot.core.domain.ExampleService 7 | import io.dodn.springboot.core.support.response.ApiResponse 8 | import org.springframework.web.bind.annotation.GetMapping 9 | import org.springframework.web.bind.annotation.PathVariable 10 | import org.springframework.web.bind.annotation.PostMapping 11 | import org.springframework.web.bind.annotation.RequestBody 12 | import org.springframework.web.bind.annotation.RequestParam 13 | import org.springframework.web.bind.annotation.RestController 14 | 15 | @RestController 16 | class ExampleController( 17 | val exampleExampleService: ExampleService, 18 | ) { 19 | @GetMapping("/get/{exampleValue}") 20 | fun exampleGet( 21 | @PathVariable exampleValue: String, 22 | @RequestParam exampleParam: String, 23 | ): ApiResponse { 24 | val result = exampleExampleService.processExample(ExampleData(exampleValue, exampleParam)) 25 | return ApiResponse.success(ExampleResponseDto(result.data)) 26 | } 27 | 28 | @PostMapping("/post") 29 | fun examplePost( 30 | @RequestBody request: ExampleRequestDto, 31 | ): ApiResponse { 32 | val result = exampleExampleService.processExample(request.toExampleData()) 33 | return ApiResponse.success(ExampleResponseDto(result.data)) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/v1/request/ExampleRequestDto.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller.v1.request 2 | 3 | import io.dodn.springboot.core.domain.ExampleData 4 | 5 | data class ExampleRequestDto( 6 | val data: String, 7 | ) { 8 | fun toExampleData(): ExampleData { 9 | return ExampleData(data, data) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/api/controller/v1/response/ExampleResponseDto.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller.v1.response 2 | 3 | data class ExampleResponseDto( 4 | val result: String, 5 | ) 6 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/domain/ExampleData.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.domain 2 | 3 | data class ExampleData( 4 | val value: String, 5 | val param: String, 6 | ) 7 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/domain/ExampleResult.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.domain 2 | 3 | data class ExampleResult( 4 | val data: String, 5 | ) 6 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/domain/ExampleService.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.domain 2 | 3 | import org.springframework.stereotype.Service 4 | 5 | @Service 6 | class ExampleService() { 7 | fun processExample(exampleData: ExampleData): ExampleResult { 8 | return ExampleResult(exampleData.value) 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/CoreException.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error 2 | 3 | class CoreException( 4 | val errorType: ErrorType, 5 | val data: Any? = null, 6 | ) : RuntimeException(errorType.message) 7 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorCode.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error 2 | 3 | enum class ErrorCode { 4 | E500, 5 | } 6 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorMessage.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error 2 | 3 | data class ErrorMessage private constructor( 4 | val code: String, 5 | val message: String, 6 | val data: Any? = null, 7 | ) { 8 | constructor(errorType: ErrorType, data: Any? = null) : this( 9 | code = errorType.code.name, 10 | message = errorType.message, 11 | data = data, 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/support/error/ErrorType.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error 2 | 3 | import org.springframework.boot.logging.LogLevel 4 | import org.springframework.http.HttpStatus 5 | 6 | enum class ErrorType(val status: HttpStatus, val code: ErrorCode, val message: String, val logLevel: LogLevel) { 7 | DEFAULT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.E500, "An unexpected error has occurred.", LogLevel.ERROR), 8 | } 9 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ApiResponse.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.response 2 | 3 | import io.dodn.springboot.core.support.error.ErrorMessage 4 | import io.dodn.springboot.core.support.error.ErrorType 5 | 6 | data class ApiResponse private constructor( 7 | val result: ResultType, 8 | val data: T? = null, 9 | val error: ErrorMessage? = null, 10 | ) { 11 | companion object { 12 | fun success(): ApiResponse { 13 | return ApiResponse(ResultType.SUCCESS, null, null) 14 | } 15 | 16 | fun success(data: S): ApiResponse { 17 | return ApiResponse(ResultType.SUCCESS, data, null) 18 | } 19 | 20 | fun error(error: ErrorType, errorData: Any? = null): ApiResponse { 21 | return ApiResponse(ResultType.ERROR, null, ErrorMessage(error, errorData)) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/core-api/src/main/kotlin/io/dodn/springboot/core/support/response/ResultType.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.response 2 | 3 | enum class ResultType { 4 | SUCCESS, 5 | ERROR, 6 | } 7 | -------------------------------------------------------------------------------- /core/core-api/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring.application.name: core-api 2 | spring.profiles.active: local 3 | 4 | spring: 5 | config: 6 | import: 7 | - monitoring.yml 8 | - logging.yml 9 | - db-core.yml 10 | - client-example.yml 11 | web.resources.add-mappings: false 12 | 13 | server: 14 | tomcat: 15 | max-connections: 20000 16 | threads: 17 | max: 600 18 | min-spare: 100 19 | 20 | --- 21 | spring.config.activate.on-profile: local 22 | 23 | 24 | --- 25 | spring.config.activate.on-profile: local-dev 26 | 27 | 28 | --- 29 | spring.config.activate.on-profile: dev 30 | 31 | 32 | --- 33 | spring.config.activate.on-profile: staging 34 | 35 | 36 | --- 37 | spring.config.activate.on-profile: live 38 | 39 | -------------------------------------------------------------------------------- /core/core-api/src/test/kotlin/io/dodn/springboot/ContextTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot 2 | 3 | import org.junit.jupiter.api.Tag 4 | import org.springframework.boot.test.context.SpringBootTest 5 | import org.springframework.test.context.TestConstructor 6 | 7 | @Tag("context") 8 | @SpringBootTest 9 | @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) 10 | abstract class ContextTest 11 | -------------------------------------------------------------------------------- /core/core-api/src/test/kotlin/io/dodn/springboot/CoreApiApplicationTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot 2 | 3 | import org.junit.jupiter.api.Test 4 | 5 | internal class CoreApiApplicationTest : ContextTest() { 6 | @Test 7 | fun shouldBeLoadedContext() { 8 | // it should be passed 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/core-api/src/test/kotlin/io/dodn/springboot/DevelopTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot 2 | 3 | import org.junit.jupiter.api.Tag 4 | import org.springframework.boot.test.context.SpringBootTest 5 | import org.springframework.test.context.TestConstructor 6 | 7 | @Tag("develop") 8 | @SpringBootTest 9 | @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) 10 | abstract class DevelopTest 11 | -------------------------------------------------------------------------------- /core/core-api/src/test/kotlin/io/dodn/springboot/core/api/controller/v1/ExampleControllerTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller.v1 2 | 3 | import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto 4 | import io.dodn.springboot.core.domain.ExampleResult 5 | import io.dodn.springboot.core.domain.ExampleService 6 | import io.dodn.springboot.test.api.RestDocsTest 7 | import io.dodn.springboot.test.api.RestDocsUtils.requestPreprocessor 8 | import io.dodn.springboot.test.api.RestDocsUtils.responsePreprocessor 9 | import io.mockk.every 10 | import io.mockk.mockk 11 | import io.restassured.http.ContentType 12 | import org.junit.jupiter.api.BeforeEach 13 | import org.junit.jupiter.api.Test 14 | import org.springframework.http.HttpStatus 15 | import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document 16 | import org.springframework.restdocs.payload.JsonFieldType 17 | import org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath 18 | import org.springframework.restdocs.payload.PayloadDocumentation.requestFields 19 | import org.springframework.restdocs.payload.PayloadDocumentation.responseFields 20 | import org.springframework.restdocs.request.RequestDocumentation 21 | import org.springframework.restdocs.request.RequestDocumentation.parameterWithName 22 | import org.springframework.restdocs.request.RequestDocumentation.queryParameters 23 | 24 | class ExampleControllerTest : RestDocsTest() { 25 | private lateinit var exampleService: ExampleService 26 | private lateinit var controller: ExampleController 27 | 28 | @BeforeEach 29 | fun setUp() { 30 | exampleService = mockk() 31 | controller = ExampleController(exampleService) 32 | mockMvc = mockController(controller) 33 | } 34 | 35 | @Test 36 | fun exampleGet() { 37 | every { exampleService.processExample(any()) } returns ExampleResult("BYE") 38 | 39 | given() 40 | .contentType(ContentType.JSON) 41 | .queryParam("exampleParam", "HELLO_PARAM") 42 | .get("/get/{exampleValue}", "HELLO_PATH") 43 | .then() 44 | .status(HttpStatus.OK) 45 | .apply( 46 | document( 47 | "exampleGet", 48 | requestPreprocessor(), 49 | responsePreprocessor(), 50 | RequestDocumentation.pathParameters( 51 | parameterWithName("exampleValue").description("ExampleValue"), 52 | ), 53 | queryParameters( 54 | parameterWithName("exampleParam").description("ExampleParam"), 55 | ), 56 | responseFields( 57 | fieldWithPath("result").type(JsonFieldType.STRING).description("ResultType"), 58 | fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Date"), 59 | fieldWithPath("error").type(JsonFieldType.NULL).ignored(), 60 | ), 61 | ), 62 | ) 63 | } 64 | 65 | @Test 66 | fun examplePost() { 67 | every { exampleService.processExample(any()) } returns ExampleResult("BYE") 68 | 69 | given() 70 | .contentType(ContentType.JSON) 71 | .body(ExampleRequestDto("HELLO_BODY")) 72 | .post("/post") 73 | .then() 74 | .status(HttpStatus.OK) 75 | .apply( 76 | document( 77 | "examplePost", 78 | requestPreprocessor(), 79 | responsePreprocessor(), 80 | requestFields( 81 | fieldWithPath("data").type(JsonFieldType.STRING).description("ExampleBody Data Field"), 82 | ), 83 | responseFields( 84 | fieldWithPath("result").type(JsonFieldType.STRING).description("ResultType"), 85 | fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Date"), 86 | fieldWithPath("error").type(JsonFieldType.STRING).ignored(), 87 | ), 88 | ), 89 | ) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /core/core-enum/build.gradle.kts: -------------------------------------------------------------------------------- 1 | // If you need a dependency, add it. 2 | -------------------------------------------------------------------------------- /core/core-enum/src/main/kotlin/io/dodn/springboot/core/enums/ExampleEnum.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.enums 2 | 3 | enum class ExampleEnum 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ### Application version ### 2 | applicationVersion=0.0.1-SNAPSHOT 3 | 4 | ### Project configs ### 5 | projectGroup=io.dodn.springboot 6 | 7 | ### Project dependency versions ### 8 | kotlinVersion=1.9.25 9 | javaVersion=21 10 | 11 | ### Plugin dependency versions ### 12 | asciidoctorConvertVersion=3.3.2 13 | ktlintVersion=12.3.0 14 | 15 | ### Spring dependency versions ### 16 | springBootVersion=3.4.6 17 | springDependencyManagementVersion=1.1.7 18 | springCloudDependenciesVersion=2024.0.1 19 | 20 | ### External dependency versions ### 21 | springMockkVersion=4.0.2 22 | sentryVersion=8.12.0 23 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/team-dodn/spring-boot-kotlin-template/0c4c4db50398ae5b5120609f1ea11abd440bc5a4/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.11.1-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /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 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s 90 | ' "$PWD" ) || exit 91 | 92 | # Use the maximum available, or set MAX_FD != -1 to use that value. 93 | MAX_FD=maximum 94 | 95 | warn () { 96 | echo "$*" 97 | } >&2 98 | 99 | die () { 100 | echo 101 | echo "$*" 102 | echo 103 | exit 1 104 | } >&2 105 | 106 | # OS specific support (must be 'true' or 'false'). 107 | cygwin=false 108 | msys=false 109 | darwin=false 110 | nonstop=false 111 | case "$( uname )" in #( 112 | CYGWIN* ) cygwin=true ;; #( 113 | Darwin* ) darwin=true ;; #( 114 | MSYS* | MINGW* ) msys=true ;; #( 115 | NONSTOP* ) nonstop=true ;; 116 | esac 117 | 118 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 119 | 120 | 121 | # Determine the Java command to use to start the JVM. 122 | if [ -n "$JAVA_HOME" ] ; then 123 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 124 | # IBM's JDK on AIX uses strange locations for the executables 125 | JAVACMD=$JAVA_HOME/jre/sh/java 126 | else 127 | JAVACMD=$JAVA_HOME/bin/java 128 | fi 129 | if [ ! -x "$JAVACMD" ] ; then 130 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 131 | 132 | Please set the JAVA_HOME variable in your environment to match the 133 | location of your Java installation." 134 | fi 135 | else 136 | JAVACMD=java 137 | if ! command -v java >/dev/null 2>&1 138 | then 139 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 140 | 141 | Please set the JAVA_HOME variable in your environment to match the 142 | location of your Java installation." 143 | fi 144 | fi 145 | 146 | # Increase the maximum file descriptors if we can. 147 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 148 | case $MAX_FD in #( 149 | max*) 150 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 151 | # shellcheck disable=SC2039,SC3045 152 | MAX_FD=$( ulimit -H -n ) || 153 | warn "Could not query maximum file descriptor limit" 154 | esac 155 | case $MAX_FD in #( 156 | '' | soft) :;; #( 157 | *) 158 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 159 | # shellcheck disable=SC2039,SC3045 160 | ulimit -n "$MAX_FD" || 161 | warn "Could not set maximum file descriptor limit to $MAX_FD" 162 | esac 163 | fi 164 | 165 | # Collect all arguments for the java command, stacking in reverse order: 166 | # * args from the command line 167 | # * the main class name 168 | # * -classpath 169 | # * -D...appname settings 170 | # * --module-path (only if needed) 171 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 172 | 173 | # For Cygwin or MSYS, switch paths to Windows format before running java 174 | if "$cygwin" || "$msys" ; then 175 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 176 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 177 | 178 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 179 | 180 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 181 | for arg do 182 | if 183 | case $arg in #( 184 | -*) false ;; # don't mess with options #( 185 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 186 | [ -e "$t" ] ;; #( 187 | *) false ;; 188 | esac 189 | then 190 | arg=$( cygpath --path --ignore --mixed "$arg" ) 191 | fi 192 | # Roll the args list around exactly as many times as the number of 193 | # args, so each arg winds up back in the position where it started, but 194 | # possibly modified. 195 | # 196 | # NB: a `for` loop captures its iteration list before it begins, so 197 | # changing the positional parameters here affects neither the number of 198 | # iterations, nor the values presented in `arg`. 199 | shift # remove old arg 200 | set -- "$@" "$arg" # push replacement arg 201 | done 202 | fi 203 | 204 | 205 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 206 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 207 | 208 | # Collect all arguments for the java command: 209 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 210 | # and any embedded shellness will be escaped. 211 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 212 | # treated as '${Hostname}' itself on the command line. 213 | 214 | set -- \ 215 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 216 | -classpath "$CLASSPATH" \ 217 | org.gradle.wrapper.GradleWrapperMain \ 218 | "$@" 219 | 220 | # Stop when "xargs" is not available. 221 | if ! command -v xargs >/dev/null 2>&1 222 | then 223 | die "xargs is not available" 224 | fi 225 | 226 | # Use "xargs" to parse quoted args. 227 | # 228 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 229 | # 230 | # In Bash we could simply go: 231 | # 232 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 233 | # set -- "${ARGS[@]}" "$@" 234 | # 235 | # but POSIX shell has neither arrays nor command substitution, so instead we 236 | # post-process each arg (as a line of input to sed) to backslash-escape any 237 | # character that might be a shell metacharacter, then use eval to reverse 238 | # that process (while maintaining the separation between arguments), and wrap 239 | # the whole thing up as a single "set" statement. 240 | # 241 | # This will of course break if any of these variables contains a newline or 242 | # an unmatched quote. 243 | # 244 | 245 | eval "set -- $( 246 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 247 | xargs -n1 | 248 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 249 | tr '\n' ' ' 250 | )" '"$@"' 251 | 252 | exec "$JAVACMD" "$@" 253 | -------------------------------------------------------------------------------- /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 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "spring-boot-kotlin-template" 2 | 3 | include( 4 | "core:core-enum", 5 | "core:core-api", 6 | "storage:db-core", 7 | "tests:api-docs", 8 | "support:logging", 9 | "support:monitoring", 10 | "clients:client-example" 11 | ) 12 | 13 | pluginManagement { 14 | val kotlinVersion: String by settings 15 | val springBootVersion: String by settings 16 | val springDependencyManagementVersion: String by settings 17 | val asciidoctorConvertVersion: 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.kapt" -> useVersion(kotlinVersion) 25 | "org.jetbrains.kotlin.plugin.spring" -> useVersion(kotlinVersion) 26 | "org.jetbrains.kotlin.plugin.jpa" -> useVersion(kotlinVersion) 27 | "org.springframework.boot" -> useVersion(springBootVersion) 28 | "io.spring.dependency-management" -> useVersion(springDependencyManagementVersion) 29 | "org.asciidoctor.jvm.convert" -> useVersion(asciidoctorConvertVersion) 30 | "org.jlleitschuh.gradle.ktlint" -> useVersion(ktlintVersion) 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /storage/db-core/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 | api("org.springframework.boot:spring-boot-starter-data-jpa") 9 | runtimeOnly("com.mysql:mysql-connector-j") 10 | runtimeOnly("com.h2database:h2") 11 | } 12 | -------------------------------------------------------------------------------- /storage/db-core/src/main/kotlin/io/dodn/springboot/storage/db/core/BaseEntity.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core 2 | 3 | import jakarta.persistence.GeneratedValue 4 | import jakarta.persistence.GenerationType 5 | import jakarta.persistence.Id 6 | import jakarta.persistence.MappedSuperclass 7 | import org.hibernate.annotations.CreationTimestamp 8 | import org.hibernate.annotations.UpdateTimestamp 9 | import java.time.LocalDateTime 10 | 11 | @MappedSuperclass 12 | abstract class BaseEntity { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | val id: Long = 0 16 | 17 | @CreationTimestamp 18 | val createdAt: LocalDateTime = LocalDateTime.MIN 19 | 20 | @UpdateTimestamp 21 | val updatedAt: LocalDateTime = LocalDateTime.MIN 22 | } 23 | -------------------------------------------------------------------------------- /storage/db-core/src/main/kotlin/io/dodn/springboot/storage/db/core/ExampleEntity.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core 2 | 3 | import jakarta.persistence.Column 4 | import jakarta.persistence.Entity 5 | 6 | @Entity 7 | class ExampleEntity( 8 | @Column 9 | val exampleColumn: String, 10 | ) : BaseEntity() 11 | -------------------------------------------------------------------------------- /storage/db-core/src/main/kotlin/io/dodn/springboot/storage/db/core/ExampleRepository.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository 4 | 5 | interface ExampleRepository : JpaRepository 6 | -------------------------------------------------------------------------------- /storage/db-core/src/main/kotlin/io/dodn/springboot/storage/db/core/config/CoreDataSourceConfig.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core.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 CoreDataSourceConfig { 12 | @Bean 13 | @ConfigurationProperties(prefix = "storage.datasource.core") 14 | fun coreHikariConfig(): HikariConfig { 15 | return HikariConfig() 16 | } 17 | 18 | @Bean 19 | fun coreDataSource(@Qualifier("coreHikariConfig") config: HikariConfig): HikariDataSource { 20 | return HikariDataSource(config) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /storage/db-core/src/main/kotlin/io/dodn/springboot/storage/db/core/config/CoreJpaConfig.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core.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 = ["io.dodn.springboot.storage.db.core"]) 11 | @EnableJpaRepositories(basePackages = ["io.dodn.springboot.storage.db.core"]) 12 | internal class CoreJpaConfig 13 | -------------------------------------------------------------------------------- /storage/db-core/src/main/resources/db-core.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | jpa: 3 | open-in-view: false 4 | hibernate: 5 | ddl-auto: validate 6 | properties: 7 | hibernate.default_batch_fetch_size: 100 8 | 9 | --- 10 | spring.config.activate.on-profile: local 11 | 12 | spring: 13 | jpa: 14 | hibernate: 15 | ddl-auto: create 16 | properties: 17 | hibernate: 18 | format_sql: true 19 | show_sql: true 20 | h2: 21 | console: 22 | enabled: true 23 | 24 | storage: 25 | datasource: 26 | core: 27 | driver-class-name: org.h2.Driver 28 | jdbc-url: jdbc:h2:mem:core;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 29 | username: sa 30 | pool-name: core-db-pool 31 | data-source-properties: 32 | rewriteBatchedStatements: true 33 | 34 | --- 35 | spring.config.activate.on-profile: local-dev 36 | 37 | spring: 38 | jpa: 39 | properties: 40 | hibernate: 41 | format_sql: true 42 | show_sql: true 43 | 44 | storage: 45 | datasource: 46 | core: 47 | driver-class-name: com.mysql.cj.jdbc.Driver 48 | jdbc-url: jdbc:mysql://${storage.database.core-db.url} 49 | username: ${storage.database.core-db.username} 50 | password: ${storage.database.core-db.password} 51 | maximum-pool-size: 5 52 | connection-timeout: 1100 53 | keepalive-time: 30000 54 | validation-timeout: 1000 55 | max-lifetime: 600000 56 | pool-name: core-db-pool 57 | data-source-properties: 58 | socketTimeout: 3000 59 | cachePrepStmts: true 60 | prepStmtCacheSize: 250 61 | prepStmtCacheSqlLimit: 2048 62 | useServerPrepStmts: true 63 | useLocalSessionState: true 64 | rewriteBatchedStatements: true 65 | cacheResultSetMetadata: true 66 | cacheServerConfiguration: true 67 | elideSetAutoCommits: true 68 | maintainTimeStats: false 69 | 70 | --- 71 | spring.config.activate.on-profile: dev 72 | 73 | storage: 74 | datasource: 75 | core: 76 | driver-class-name: com.mysql.cj.jdbc.Driver 77 | jdbc-url: jdbc:mysql://${storage.database.core-db.url} 78 | username: ${storage.database.core-db.username} 79 | password: ${storage.database.core-db.password} 80 | maximum-pool-size: 5 81 | connection-timeout: 1100 82 | keepalive-time: 30000 83 | validation-timeout: 1000 84 | max-lifetime: 600000 85 | pool-name: core-db-pool 86 | data-source-properties: 87 | socketTimeout: 3000 88 | cachePrepStmts: true 89 | prepStmtCacheSize: 250 90 | prepStmtCacheSqlLimit: 2048 91 | useServerPrepStmts: true 92 | useLocalSessionState: true 93 | rewriteBatchedStatements: true 94 | cacheResultSetMetadata: true 95 | cacheServerConfiguration: true 96 | elideSetAutoCommits: true 97 | maintainTimeStats: false 98 | 99 | --- 100 | spring.config.activate.on-profile: staging 101 | 102 | storage: 103 | datasource: 104 | core: 105 | driver-class-name: com.mysql.cj.jdbc.Driver 106 | jdbc-url: jdbc:mysql://${storage.database.core-db.url} 107 | username: ${storage.database.core-db.username} 108 | password: ${storage.database.core-db.password} 109 | maximum-pool-size: 5 110 | connection-timeout: 1100 111 | keepalive-time: 30000 112 | validation-timeout: 1000 113 | max-lifetime: 600000 114 | pool-name: core-db-pool 115 | data-source-properties: 116 | socketTimeout: 3000 117 | cachePrepStmts: true 118 | prepStmtCacheSize: 250 119 | prepStmtCacheSqlLimit: 2048 120 | useServerPrepStmts: true 121 | useLocalSessionState: true 122 | rewriteBatchedStatements: true 123 | cacheResultSetMetadata: true 124 | cacheServerConfiguration: true 125 | elideSetAutoCommits: true 126 | maintainTimeStats: false 127 | 128 | --- 129 | spring.config.activate.on-profile: live 130 | 131 | storage: 132 | datasource: 133 | core: 134 | driver-class-name: com.mysql.cj.jdbc.Driver 135 | jdbc-url: jdbc:mysql://${storage.database.core-db.url} 136 | username: ${storage.database.core-db.username} 137 | password: ${storage.database.core-db.password} 138 | maximum-pool-size: 25 139 | connection-timeout: 1100 140 | keepalive-time: 30000 141 | validation-timeout: 1000 142 | max-lifetime: 600000 143 | pool-name: core-db-pool 144 | data-source-properties: 145 | socketTimeout: 3000 146 | cachePrepStmts: true 147 | prepStmtCacheSize: 250 148 | prepStmtCacheSqlLimit: 2048 149 | useServerPrepStmts: true 150 | useLocalSessionState: true 151 | rewriteBatchedStatements: true 152 | cacheResultSetMetadata: true 153 | cacheServerConfiguration: true 154 | elideSetAutoCommits: true 155 | maintainTimeStats: false -------------------------------------------------------------------------------- /storage/db-core/src/test/kotlin/io/dodn/springboot/storage/db/CoreDbContextTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db 2 | 3 | import org.junit.jupiter.api.Tag 4 | import org.springframework.boot.test.context.SpringBootTest 5 | import org.springframework.test.context.ActiveProfiles 6 | import org.springframework.test.context.TestConstructor 7 | 8 | @ActiveProfiles("local") 9 | @Tag("context") 10 | @SpringBootTest 11 | @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) 12 | abstract class CoreDbContextTest 13 | -------------------------------------------------------------------------------- /storage/db-core/src/test/kotlin/io/dodn/springboot/storage/db/CoreDbTestApplication.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan 5 | import org.springframework.boot.runApplication 6 | 7 | @ConfigurationPropertiesScan 8 | @SpringBootApplication 9 | class CoreDbTestApplication 10 | 11 | fun main(args: Array) { 12 | runApplication(*args) 13 | } 14 | -------------------------------------------------------------------------------- /storage/db-core/src/test/kotlin/io/dodn/springboot/storage/db/core/ExampleRepositoryIT.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core 2 | 3 | import io.dodn.springboot.storage.db.CoreDbContextTest 4 | import org.assertj.core.api.Assertions.assertThat 5 | import org.junit.jupiter.api.Test 6 | 7 | class ExampleRepositoryIT( 8 | val exampleRepository: ExampleRepository, 9 | ) : CoreDbContextTest() { 10 | @Test 11 | fun testShouldBeSavedAndFound() { 12 | val saved = exampleRepository.save(ExampleEntity("SPRING_BOOT")) 13 | assertThat(saved.exampleColumn).isEqualTo("SPRING_BOOT") 14 | 15 | val found = exampleRepository.findById(saved.id).get() 16 | assertThat(found.exampleColumn).isEqualTo("SPRING_BOOT") 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /storage/db-core/src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring.application.name: db-core-test 2 | 3 | spring: 4 | config: 5 | import: 6 | - db-core.yml 7 | -------------------------------------------------------------------------------- /support/logging/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation("io.micrometer:micrometer-tracing-bridge-brave") 3 | implementation("io.sentry:sentry-logback:${property("sentryVersion")}") 4 | } 5 | -------------------------------------------------------------------------------- /support/logging/src/main/resources/logback/logback-dev.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 | YOUR_DSN 15 | 16 | WARN 17 | INFO 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /support/logging/src/main/resources/logback/logback-live.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 | YOUR_DSN 15 | 16 | WARN 17 | INFO 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /support/logging/src/main/resources/logback/logback-local-dev.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 | 19 | -------------------------------------------------------------------------------- /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 | 19 | -------------------------------------------------------------------------------- /support/logging/src/main/resources/logback/logback-staging.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 | YOUR_DSN 15 | 16 | WARN 17 | INFO 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /support/logging/src/main/resources/logging.yml: -------------------------------------------------------------------------------- 1 | logging.config: classpath:logback/logback-${spring.profiles.active}.xml -------------------------------------------------------------------------------- /support/monitoring/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation("org.springframework.boot:spring-boot-starter-actuator") 3 | implementation("io.micrometer:micrometer-registry-prometheus") 4 | } 5 | -------------------------------------------------------------------------------- /support/monitoring/src/main/resources/monitoring.yml: -------------------------------------------------------------------------------- 1 | management: 2 | endpoints: 3 | web: 4 | exposure: 5 | include: prometheus 6 | -------------------------------------------------------------------------------- /tests/api-docs/build.gradle.kts: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compileOnly("jakarta.servlet:jakarta.servlet-api") 3 | compileOnly("org.springframework.boot:spring-boot-starter-test") 4 | api("org.springframework.restdocs:spring-restdocs-mockmvc") 5 | api("org.springframework.restdocs:spring-restdocs-restassured") 6 | api("io.rest-assured:spring-mock-mvc") 7 | } 8 | -------------------------------------------------------------------------------- /tests/api-docs/src/main/kotlin/io/dodn/springboot/test/api/RestDocsTest.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.test.api 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper 4 | import com.fasterxml.jackson.databind.SerializationFeature 5 | import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper 6 | import io.restassured.module.mockmvc.RestAssuredMockMvc 7 | import io.restassured.module.mockmvc.specification.MockMvcRequestSpecification 8 | import org.junit.jupiter.api.BeforeEach 9 | import org.junit.jupiter.api.Tag 10 | import org.junit.jupiter.api.extension.ExtendWith 11 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter 12 | import org.springframework.restdocs.RestDocumentationContextProvider 13 | import org.springframework.restdocs.RestDocumentationExtension 14 | import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation 15 | import org.springframework.test.web.servlet.MockMvc 16 | import org.springframework.test.web.servlet.setup.MockMvcBuilders 17 | import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder 18 | 19 | @Tag("restdocs") 20 | @ExtendWith(RestDocumentationExtension::class) 21 | abstract class RestDocsTest { 22 | lateinit var mockMvc: MockMvcRequestSpecification 23 | private lateinit var restDocumentation: RestDocumentationContextProvider 24 | 25 | @BeforeEach 26 | fun setUp(restDocumentation: RestDocumentationContextProvider) { 27 | this.restDocumentation = restDocumentation 28 | } 29 | 30 | protected fun given(): MockMvcRequestSpecification { 31 | return mockMvc 32 | } 33 | 34 | protected fun mockController(controller: Any): MockMvcRequestSpecification { 35 | val mockMvc = createMockMvc(controller) 36 | return RestAssuredMockMvc.given() 37 | .mockMvc(mockMvc) 38 | } 39 | 40 | private fun createMockMvc(controller: Any): MockMvc { 41 | val converter = MappingJackson2HttpMessageConverter(objectMapper()) 42 | 43 | return MockMvcBuilders.standaloneSetup(controller) 44 | .apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation)) 45 | .setMessageConverters(converter) 46 | .build() 47 | } 48 | 49 | private fun objectMapper(): ObjectMapper { 50 | return jacksonObjectMapper() 51 | .findAndRegisterModules() 52 | .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) 53 | .disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/api-docs/src/main/kotlin/io/dodn/springboot/test/api/RestDocsUtils.kt: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.test.api 2 | 3 | import org.springframework.restdocs.operation.preprocess.OperationRequestPreprocessor 4 | import org.springframework.restdocs.operation.preprocess.OperationResponsePreprocessor 5 | import org.springframework.restdocs.operation.preprocess.Preprocessors 6 | 7 | object RestDocsUtils { 8 | fun requestPreprocessor(): OperationRequestPreprocessor { 9 | return Preprocessors.preprocessRequest( 10 | Preprocessors.modifyUris().scheme("http").host("dev.dodn.io").removePort(), 11 | Preprocessors.prettyPrint(), 12 | ) 13 | } 14 | 15 | fun responsePreprocessor(): OperationResponsePreprocessor { 16 | return Preprocessors.preprocessResponse(Preprocessors.prettyPrint()) 17 | } 18 | } 19 | --------------------------------------------------------------------------------