├── .gitattributes ├── .githooks └── pre-commit ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .springjavaformatconfig ├── LICENCE.md ├── README.md ├── build.gradle ├── clients └── client-example │ ├── build.gradle │ └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── dodn │ │ │ └── springboot │ │ │ └── client │ │ │ └── example │ │ │ ├── ExampleApi.java │ │ │ ├── ExampleClient.java │ │ │ ├── ExampleConfig.java │ │ │ ├── ExampleRequestDto.java │ │ │ ├── ExampleResponseDto.java │ │ │ └── model │ │ │ └── ExampleClientResult.java │ └── resources │ │ └── client-example.yml │ └── test │ ├── java │ └── io │ │ └── dodn │ │ └── springboot │ │ └── client │ │ ├── ClientExampleContextTest.java │ │ ├── ClientExampleTestApplication.java │ │ └── example │ │ └── ExampleClientTest.java │ └── resources │ └── application.yml ├── core ├── core-api │ ├── build.gradle │ └── src │ │ ├── docs │ │ └── asciidoc │ │ │ └── index.adoc │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── dodn │ │ │ │ └── springboot │ │ │ │ ├── CoreApiApplication.java │ │ │ │ └── core │ │ │ │ ├── api │ │ │ │ ├── config │ │ │ │ │ ├── AsyncConfig.java │ │ │ │ │ └── AsyncExceptionHandler.java │ │ │ │ └── controller │ │ │ │ │ ├── ApiControllerAdvice.java │ │ │ │ │ ├── HealthController.java │ │ │ │ │ └── v1 │ │ │ │ │ ├── ExampleController.java │ │ │ │ │ ├── request │ │ │ │ │ └── ExampleRequestDto.java │ │ │ │ │ └── response │ │ │ │ │ └── ExampleResponseDto.java │ │ │ │ ├── domain │ │ │ │ ├── ExampleData.java │ │ │ │ ├── ExampleResult.java │ │ │ │ └── ExampleService.java │ │ │ │ └── support │ │ │ │ ├── error │ │ │ │ ├── CoreException.java │ │ │ │ ├── ErrorCode.java │ │ │ │ ├── ErrorMessage.java │ │ │ │ └── ErrorType.java │ │ │ │ └── response │ │ │ │ ├── ApiResponse.java │ │ │ │ └── ResultType.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── io │ │ └── dodn │ │ └── springboot │ │ ├── ContextTest.java │ │ ├── CoreApiApplicationTest.java │ │ ├── DevelopTest.java │ │ └── core │ │ └── api │ │ └── controller │ │ └── v1 │ │ └── ExampleControllerTest.java └── core-enum │ ├── build.gradle │ └── src │ └── main │ └── java │ └── io │ └── dodn │ └── springboot │ └── core │ └── enums │ └── ExampleEnum.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lint.gradle ├── settings.gradle ├── storage └── db-core │ ├── build.gradle │ └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── dodn │ │ │ └── springboot │ │ │ └── storage │ │ │ └── db │ │ │ └── core │ │ │ ├── BaseEntity.java │ │ │ ├── ExampleEntity.java │ │ │ ├── ExampleRepository.java │ │ │ └── config │ │ │ ├── CoreDataSourceConfig.java │ │ │ └── CoreJpaConfig.java │ └── resources │ │ └── db-core.yml │ └── test │ ├── java │ └── io │ │ └── dodn │ │ └── springboot │ │ └── storage │ │ └── db │ │ ├── CoreDbContextTest.java │ │ ├── CoreDbTestApplication.java │ │ └── core │ │ └── ExampleRepositoryIT.java │ └── resources │ └── application.yml ├── support ├── logging │ ├── build.gradle │ └── 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 │ └── src │ └── main │ └── resources │ └── monitoring.yml └── tests └── api-docs ├── build.gradle └── src └── main └── java └── io └── dodn └── springboot └── test └── api ├── RestDocsTest.java └── RestDocsUtils.java /.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 checkFormat 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: checkFormat 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 | -------------------------------------------------------------------------------- /.springjavaformatconfig: -------------------------------------------------------------------------------- 1 | indentation-style=spaces -------------------------------------------------------------------------------- /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 Java 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-java-template/actions/workflows/ci.yml/badge.svg)](https://github.com/team-dodn/spring-boot-java-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`. 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` 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 | If you want to apply lint settings to the format of IDEA, please refer to the guide below. 134 | 135 | [Spring Java Format IntelliJ IDEA](https://github.com/spring-io/spring-javaformat#intellij-idea) 136 | 137 | --- 138 | 139 | # Supported By 140 |
JetBrains Logo (Main) logo.
141 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'org.springframework.boot' apply(false) 4 | id 'io.spring.dependency-management' 5 | id 'io.spring.javaformat' apply(false) 6 | id 'org.asciidoctor.jvm.convert' apply(false) 7 | } 8 | 9 | apply from: 'lint.gradle' 10 | 11 | allprojects { 12 | group = "${projectGroup}" 13 | version = "${applicationVersion}" 14 | sourceCompatibility = project.javaVersion 15 | 16 | repositories { 17 | mavenCentral() 18 | } 19 | } 20 | 21 | subprojects { 22 | apply plugin: 'java-library' 23 | apply plugin: 'org.springframework.boot' 24 | apply plugin: 'io.spring.dependency-management' 25 | apply plugin: 'org.asciidoctor.jvm.convert' 26 | 27 | dependencyManagement { 28 | imports { 29 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudDependenciesVersion}" 30 | } 31 | } 32 | 33 | dependencies { 34 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 35 | } 36 | 37 | bootJar.enabled = false 38 | jar.enabled = true 39 | 40 | test { 41 | useJUnitPlatform { 42 | excludeTags('develop', 'restdocs') 43 | } 44 | } 45 | 46 | tasks.register('unitTest', Test) { 47 | group = 'verification' 48 | useJUnitPlatform { 49 | excludeTags('develop', 'context', 'restdocs') 50 | } 51 | } 52 | 53 | tasks.register('contextTest', Test) { 54 | group = 'verification' 55 | useJUnitPlatform { 56 | includeTags('context') 57 | } 58 | } 59 | 60 | tasks.register('restDocsTest', Test) { 61 | group = 'verification' 62 | useJUnitPlatform { 63 | includeTags('restdocs') 64 | } 65 | } 66 | 67 | tasks.register('developTest', Test) { 68 | group = 'verification' 69 | useJUnitPlatform { 70 | includeTags('develop') 71 | } 72 | } 73 | 74 | tasks.named('asciidoctor') { 75 | dependsOn restDocsTest 76 | } 77 | } -------------------------------------------------------------------------------- /clients/client-example/build.gradle: -------------------------------------------------------------------------------- 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 | testImplementation 'com.fasterxml.jackson.core:jackson-databind' 7 | } 8 | -------------------------------------------------------------------------------- /clients/client-example/src/main/java/io/dodn/springboot/client/example/ExampleApi.java: -------------------------------------------------------------------------------- 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 | interface ExampleApi { 11 | 12 | @RequestMapping(method = RequestMethod.POST, value = "/example/example-api", 13 | consumes = MediaType.APPLICATION_JSON_VALUE) 14 | ExampleResponseDto example(@RequestBody ExampleRequestDto request); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /clients/client-example/src/main/java/io/dodn/springboot/client/example/ExampleClient.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example; 2 | 3 | import io.dodn.springboot.client.example.model.ExampleClientResult; 4 | 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class ExampleClient { 9 | 10 | private final ExampleApi exampleApi; 11 | 12 | public ExampleClient(ExampleApi exampleApi) { 13 | this.exampleApi = exampleApi; 14 | } 15 | 16 | public ExampleClientResult example(String exampleParameter) { 17 | ExampleRequestDto request = new ExampleRequestDto(exampleParameter); 18 | return exampleApi.example(request).toResult(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /clients/client-example/src/main/java/io/dodn/springboot/client/example/ExampleConfig.java: -------------------------------------------------------------------------------- 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 | class ExampleConfig { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /clients/client-example/src/main/java/io/dodn/springboot/client/example/ExampleRequestDto.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example; 2 | 3 | record ExampleRequestDto(String exampleRequestValue) { 4 | } 5 | -------------------------------------------------------------------------------- /clients/client-example/src/main/java/io/dodn/springboot/client/example/ExampleResponseDto.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example; 2 | 3 | import io.dodn.springboot.client.example.model.ExampleClientResult; 4 | 5 | record ExampleResponseDto(String exampleResponseValue) { 6 | ExampleClientResult toResult() { 7 | return new ExampleClientResult(exampleResponseValue); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /clients/client-example/src/main/java/io/dodn/springboot/client/example/model/ExampleClientResult.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example.model; 2 | 3 | public record ExampleClientResult(String exampleResult) { 4 | } 5 | -------------------------------------------------------------------------------- /clients/client-example/src/main/resources/client-example.yml: -------------------------------------------------------------------------------- 1 | example: 2 | api: 3 | url: https://default.example.example 4 | exampleValue: exampleDefaultValue 5 | 6 | spring.cloud.openfeign: 7 | client: 8 | config: 9 | example-api: 10 | connectTimeout: 2100 11 | readTimeout: 5000 12 | loggerLevel: full 13 | compression: 14 | response: 15 | enabled: false 16 | httpclient: 17 | max-connections: 2000 18 | max-connections-per-route: 500 19 | 20 | --- 21 | spring.config.activate.on-profile: local 22 | 23 | --- 24 | spring.config.activate.on-profile: 25 | - local-dev 26 | - dev 27 | 28 | --- 29 | spring.config.activate.on-profile: 30 | - staging 31 | - live 32 | 33 | example: 34 | api: 35 | url: https://live.example.example 36 | exampleValue: exampleLiveValue 37 | 38 | -------------------------------------------------------------------------------- /clients/client-example/src/test/java/io/dodn/springboot/client/ClientExampleContextTest.java: -------------------------------------------------------------------------------- 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 | public abstract class ClientExampleContextTest { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /clients/client-example/src/test/java/io/dodn/springboot/client/ClientExampleTestApplication.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan; 6 | 7 | @ConfigurationPropertiesScan 8 | @SpringBootApplication 9 | public class ClientExampleTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ClientExampleTestApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /clients/client-example/src/test/java/io/dodn/springboot/client/example/ExampleClientTest.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.client.example; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import feign.RetryableException; 6 | 7 | import io.dodn.springboot.client.ClientExampleContextTest; 8 | 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class ExampleClientTest extends ClientExampleContextTest { 12 | 13 | private final ExampleClient exampleClient; 14 | 15 | public ExampleClientTest(ExampleClient exampleClient) { 16 | this.exampleClient = exampleClient; 17 | } 18 | 19 | @Test 20 | public void shouldBeThrownExceptionWhenExample() { 21 | try { 22 | exampleClient.example("HELLO!"); 23 | } 24 | catch (Exception e) { 25 | assertThat(e).isExactlyInstanceOf(RetryableException.class); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /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: -------------------------------------------------------------------------------- 1 | bootJar.enabled = true 2 | jar.enabled = false 3 | 4 | dependencies { 5 | implementation project(":core:core-enum") 6 | implementation project(":support:monitoring") 7 | implementation project(":support:logging") 8 | implementation project(":storage:db-core") 9 | implementation project(":clients:client-example") 10 | 11 | testImplementation project(":tests:api-docs") 12 | 13 | implementation 'org.springframework.boot:spring-boot-starter-web' 14 | } -------------------------------------------------------------------------------- /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/java/io/dodn/springboot/CoreApiApplication.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan; 6 | 7 | @ConfigurationPropertiesScan 8 | @SpringBootApplication 9 | public class CoreApiApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(CoreApiApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/api/config/AsyncConfig.java: -------------------------------------------------------------------------------- 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 | 9 | import java.util.concurrent.Executor; 10 | 11 | @Configuration 12 | @EnableAsync 13 | public class AsyncConfig implements AsyncConfigurer { 14 | 15 | @Override 16 | public Executor getAsyncExecutor() { 17 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 18 | executor.setCorePoolSize(10); 19 | executor.setMaxPoolSize(10); 20 | executor.setQueueCapacity(10000); 21 | executor.setWaitForTasksToCompleteOnShutdown(true); 22 | executor.setAwaitTerminationSeconds(10); 23 | executor.initialize(); 24 | return executor; 25 | } 26 | 27 | @Override 28 | public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { 29 | return new AsyncExceptionHandler(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/api/config/AsyncExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.config; 2 | 3 | import io.dodn.springboot.core.support.error.CoreException; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; 8 | 9 | import java.lang.reflect.Method; 10 | 11 | public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler { 12 | 13 | private final Logger log = LoggerFactory.getLogger(getClass()); 14 | 15 | @Override 16 | public void handleUncaughtException(Throwable e, Method method, Object... params) { 17 | if (e instanceof CoreException) { 18 | switch (((CoreException) e).getErrorType().getLogLevel()) { 19 | case ERROR -> log.error("CoreException : {}", e.getMessage(), e); 20 | case WARN -> log.warn("CoreException : {}", e.getMessage(), e); 21 | default -> log.info("CoreException : {}", e.getMessage(), e); 22 | } 23 | } 24 | else { 25 | log.error("Exception : {}", e.getMessage(), e); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/api/controller/ApiControllerAdvice.java: -------------------------------------------------------------------------------- 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 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 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 | public class ApiControllerAdvice { 15 | 16 | private final Logger log = LoggerFactory.getLogger(getClass()); 17 | 18 | @ExceptionHandler(CoreException.class) 19 | public ResponseEntity> handleCoreException(CoreException e) { 20 | switch (e.getErrorType().getLogLevel()) { 21 | case ERROR -> log.error("CoreException : {}", e.getMessage(), e); 22 | case WARN -> log.warn("CoreException : {}", e.getMessage(), e); 23 | default -> log.info("CoreException : {}", e.getMessage(), e); 24 | } 25 | return new ResponseEntity<>(ApiResponse.error(e.getErrorType(), e.getData()), e.getErrorType().getStatus()); 26 | } 27 | 28 | @ExceptionHandler(Exception.class) 29 | public ResponseEntity> handleException(Exception e) { 30 | log.error("Exception : {}", e.getMessage(), e); 31 | return new ResponseEntity<>(ApiResponse.error(ErrorType.DEFAULT_ERROR), ErrorType.DEFAULT_ERROR.getStatus()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/api/controller/HealthController.java: -------------------------------------------------------------------------------- 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 | public class HealthController { 10 | 11 | @GetMapping("/health") 12 | public ResponseEntity health() { 13 | return ResponseEntity.status(HttpStatus.OK).build(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/api/controller/v1/ExampleController.java: -------------------------------------------------------------------------------- 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.ExampleResult; 7 | import io.dodn.springboot.core.domain.ExampleService; 8 | import io.dodn.springboot.core.support.response.ApiResponse; 9 | 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.PostMapping; 13 | import org.springframework.web.bind.annotation.RequestBody; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | @RestController 18 | public class ExampleController { 19 | 20 | private final ExampleService exampleExampleService; 21 | 22 | public ExampleController(ExampleService exampleExampleService) { 23 | this.exampleExampleService = exampleExampleService; 24 | } 25 | 26 | @GetMapping("/get/{exampleValue}") 27 | public ApiResponse exampleGet(@PathVariable String exampleValue, 28 | @RequestParam String exampleParam) { 29 | ExampleResult result = exampleExampleService.processExample(new ExampleData(exampleValue, exampleParam)); 30 | return ApiResponse.success(new ExampleResponseDto(result.data())); 31 | } 32 | 33 | @PostMapping("/post") 34 | public ApiResponse examplePost(@RequestBody ExampleRequestDto request) { 35 | ExampleResult result = exampleExampleService.processExample(request.toExampleData()); 36 | return ApiResponse.success(new ExampleResponseDto(result.data())); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/api/controller/v1/request/ExampleRequestDto.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller.v1.request; 2 | 3 | import io.dodn.springboot.core.domain.ExampleData; 4 | 5 | public record ExampleRequestDto(String data) { 6 | public ExampleData toExampleData() { 7 | return new ExampleData(data, data); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/api/controller/v1/response/ExampleResponseDto.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller.v1.response; 2 | 3 | public record ExampleResponseDto(String result) { 4 | } 5 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/domain/ExampleData.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.domain; 2 | 3 | public record ExampleData(String value, String param) { 4 | } 5 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/domain/ExampleResult.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.domain; 2 | 3 | public record ExampleResult(String data) { 4 | } 5 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/domain/ExampleService.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.domain; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public class ExampleService { 7 | 8 | public ExampleResult processExample(ExampleData exampleData) { 9 | return new ExampleResult(exampleData.value()); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/support/error/CoreException.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error; 2 | 3 | public class CoreException extends RuntimeException { 4 | 5 | private final ErrorType errorType; 6 | 7 | private final Object data; 8 | 9 | public CoreException(ErrorType errorType) { 10 | super(errorType.getMessage()); 11 | this.errorType = errorType; 12 | this.data = null; 13 | } 14 | 15 | public CoreException(ErrorType errorType, Object data) { 16 | super(errorType.getMessage()); 17 | this.errorType = errorType; 18 | this.data = data; 19 | } 20 | 21 | public ErrorType getErrorType() { 22 | return errorType; 23 | } 24 | 25 | public Object getData() { 26 | return data; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/support/error/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error; 2 | 3 | public enum ErrorCode { 4 | 5 | E500 6 | 7 | } 8 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/support/error/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error; 2 | 3 | public class ErrorMessage { 4 | 5 | private final String code; 6 | 7 | private final String message; 8 | 9 | private final Object data; 10 | 11 | public ErrorMessage(ErrorType errorType) { 12 | this.code = errorType.getCode().name(); 13 | this.message = errorType.getMessage(); 14 | this.data = null; 15 | } 16 | 17 | public ErrorMessage(ErrorType errorType, Object data) { 18 | this.code = errorType.getCode().name(); 19 | this.message = errorType.getMessage(); 20 | this.data = data; 21 | } 22 | 23 | public String getCode() { 24 | return code; 25 | } 26 | 27 | public String getMessage() { 28 | return message; 29 | } 30 | 31 | public Object getData() { 32 | return data; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/support/error/ErrorType.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.error; 2 | 3 | import org.springframework.boot.logging.LogLevel; 4 | import org.springframework.http.HttpStatus; 5 | 6 | public enum ErrorType { 7 | 8 | DEFAULT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.E500, "An unexpected error has occurred.", 9 | LogLevel.ERROR); 10 | 11 | private final HttpStatus status; 12 | 13 | private final ErrorCode code; 14 | 15 | private final String message; 16 | 17 | private final LogLevel logLevel; 18 | 19 | ErrorType(HttpStatus status, ErrorCode code, String message, LogLevel logLevel) { 20 | 21 | this.status = status; 22 | this.code = code; 23 | this.message = message; 24 | this.logLevel = logLevel; 25 | } 26 | 27 | public HttpStatus getStatus() { 28 | return status; 29 | } 30 | 31 | public ErrorCode getCode() { 32 | return code; 33 | } 34 | 35 | public String getMessage() { 36 | return message; 37 | } 38 | 39 | public LogLevel getLogLevel() { 40 | return logLevel; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/support/response/ApiResponse.java: -------------------------------------------------------------------------------- 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 | public class ApiResponse { 7 | 8 | private final ResultType result; 9 | 10 | private final S data; 11 | 12 | private final ErrorMessage error; 13 | 14 | private ApiResponse(ResultType result, S data, ErrorMessage error) { 15 | this.result = result; 16 | this.data = data; 17 | this.error = error; 18 | } 19 | 20 | public static ApiResponse success() { 21 | return new ApiResponse<>(ResultType.SUCCESS, null, null); 22 | } 23 | 24 | public static ApiResponse success(S data) { 25 | return new ApiResponse<>(ResultType.SUCCESS, data, null); 26 | } 27 | 28 | public static ApiResponse error(ErrorType error) { 29 | return new ApiResponse<>(ResultType.ERROR, null, new ErrorMessage(error)); 30 | } 31 | 32 | public static ApiResponse error(ErrorType error, Object errorData) { 33 | return new ApiResponse<>(ResultType.ERROR, null, new ErrorMessage(error, errorData)); 34 | } 35 | 36 | public ResultType getResult() { 37 | return result; 38 | } 39 | 40 | public Object getData() { 41 | return data; 42 | } 43 | 44 | public ErrorMessage getError() { 45 | return error; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /core/core-api/src/main/java/io/dodn/springboot/core/support/response/ResultType.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.support.response; 2 | 3 | public enum ResultType { 4 | 5 | SUCCESS, ERROR 6 | 7 | } 8 | -------------------------------------------------------------------------------- /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/java/io/dodn/springboot/ContextTest.java: -------------------------------------------------------------------------------- 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 | public abstract class ContextTest { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /core/core-api/src/test/java/io/dodn/springboot/CoreApiApplicationTest.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | public class CoreApiApplicationTest extends ContextTest { 6 | 7 | @Test 8 | public void shouldBeLoadedContext() { 9 | // it should be passed 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /core/core-api/src/test/java/io/dodn/springboot/DevelopTest.java: -------------------------------------------------------------------------------- 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 | public abstract class DevelopTest { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /core/core-api/src/test/java/io/dodn/springboot/core/api/controller/v1/ExampleControllerTest.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.api.controller.v1; 2 | 3 | import static io.dodn.springboot.test.api.RestDocsUtils.requestPreprocessor; 4 | import static io.dodn.springboot.test.api.RestDocsUtils.responsePreprocessor; 5 | 6 | import static org.mockito.ArgumentMatchers.any; 7 | import static org.mockito.Mockito.mock; 8 | import static org.mockito.Mockito.when; 9 | import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; 10 | import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; 11 | import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; 12 | import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; 13 | import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; 14 | import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; 15 | import static org.springframework.restdocs.request.RequestDocumentation.queryParameters; 16 | 17 | import io.dodn.springboot.core.api.controller.v1.request.ExampleRequestDto; 18 | import io.dodn.springboot.core.domain.ExampleResult; 19 | import io.dodn.springboot.core.domain.ExampleService; 20 | import io.dodn.springboot.test.api.RestDocsTest; 21 | import io.restassured.http.ContentType; 22 | 23 | import org.junit.jupiter.api.BeforeEach; 24 | import org.junit.jupiter.api.Test; 25 | import org.springframework.http.HttpStatus; 26 | import org.springframework.restdocs.payload.JsonFieldType; 27 | 28 | public class ExampleControllerTest extends RestDocsTest { 29 | 30 | private ExampleService exampleService; 31 | 32 | private ExampleController controller; 33 | 34 | @BeforeEach 35 | public void setUp() { 36 | exampleService = mock(ExampleService.class); 37 | controller = new ExampleController(exampleService); 38 | mockMvc = mockController(controller); 39 | } 40 | 41 | @Test 42 | public void exampleGet() { 43 | when(exampleService.processExample(any())).thenReturn(new ExampleResult("BYE")); 44 | 45 | given().contentType(ContentType.JSON) 46 | .queryParam("exampleParam", "HELLO_PARAM") 47 | .get("/get/{exampleValue}", "HELLO_PATH") 48 | .then() 49 | .status(HttpStatus.OK) 50 | .apply(document("exampleGet", requestPreprocessor(), responsePreprocessor(), 51 | pathParameters(parameterWithName("exampleValue").description("ExampleValue")), 52 | queryParameters(parameterWithName("exampleParam").description("ExampleParam")), 53 | responseFields(fieldWithPath("result").type(JsonFieldType.STRING).description("ResultType"), 54 | fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Date"), 55 | fieldWithPath("error").type(JsonFieldType.NULL).ignored()))); 56 | } 57 | 58 | @Test 59 | public void examplePost() { 60 | when(exampleService.processExample(any())).thenReturn(new ExampleResult("BYE")); 61 | 62 | given().contentType(ContentType.JSON) 63 | .body(new ExampleRequestDto("HELLO_BODY")) 64 | .post("/post") 65 | .then() 66 | .status(HttpStatus.OK) 67 | .apply(document("examplePost", requestPreprocessor(), responsePreprocessor(), 68 | requestFields( 69 | fieldWithPath("data").type(JsonFieldType.STRING).description("ExampleBody Data Field")), 70 | responseFields(fieldWithPath("result").type(JsonFieldType.STRING).description("ResultType"), 71 | fieldWithPath("data.result").type(JsonFieldType.STRING).description("Result Date"), 72 | fieldWithPath("error").type(JsonFieldType.STRING).ignored()))); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /core/core-enum/build.gradle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/team-dodn/spring-boot-java-template/bf7a23bb95ae8f754ee3437b6da5ab1d04f0f1ef/core/core-enum/build.gradle -------------------------------------------------------------------------------- /core/core-enum/src/main/java/io/dodn/springboot/core/enums/ExampleEnum.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.core.enums; 2 | 3 | public enum ExampleEnum { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ### Application version ### 2 | applicationVersion=0.0.1-SNAPSHOT 3 | 4 | ### Project configs ### 5 | projectGroup=io.dodn.springboot 6 | javaVersion=21 7 | 8 | ### Plugin dependency versions ### 9 | asciidoctorConvertVersion=3.3.2 10 | springJavaFormatVersion=0.0.45 11 | 12 | ### Spring dependency versions ### 13 | springBootVersion=3.4.6 14 | springDependencyManagementVersion=1.1.7 15 | springCloudDependenciesVersion=2024.0.1 16 | 17 | ### External dependency versions ### 18 | sentryVersion=8.12.0 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/team-dodn/spring-boot-java-template/bf7a23bb95ae8f754ee3437b6da5ab1d04f0f1ef/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 | -------------------------------------------------------------------------------- /lint.gradle: -------------------------------------------------------------------------------- 1 | subprojects { 2 | apply plugin: 'java' 3 | apply plugin: 'io.spring.javaformat' 4 | 5 | dependencies { 6 | compileOnly "io.spring.javaformat:spring-javaformat-gradle-plugin:${springJavaFormatVersion}" 7 | } 8 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | plugins { 3 | id 'org.springframework.boot' version "${springBootVersion}" 4 | id 'io.spring.dependency-management' version "${springDependencyManagementVersion}" 5 | id 'org.asciidoctor.jvm.convert' version "${asciidoctorConvertVersion}" 6 | id 'io.spring.javaformat' version "${springJavaFormatVersion}" 7 | } 8 | } 9 | 10 | rootProject.name = 'spring-boot-java-template' 11 | 12 | include 'core:core-enum' 13 | include 'core:core-api' 14 | include 'storage:db-core' 15 | include 'tests:api-docs' 16 | include 'support:logging' 17 | include 'support:monitoring' 18 | include 'clients:client-example' -------------------------------------------------------------------------------- /storage/db-core/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation project(':core:core-enum') 3 | api 'org.springframework.boot:spring-boot-starter-data-jpa' 4 | runtimeOnly 'com.mysql:mysql-connector-j' 5 | runtimeOnly 'com.h2database:h2' 6 | } 7 | -------------------------------------------------------------------------------- /storage/db-core/src/main/java/io/dodn/springboot/storage/db/core/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import jakarta.persistence.MappedSuperclass; 8 | 9 | import org.hibernate.annotations.CreationTimestamp; 10 | import org.hibernate.annotations.UpdateTimestamp; 11 | 12 | import java.time.LocalDateTime; 13 | 14 | @MappedSuperclass 15 | public abstract class BaseEntity { 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long id; 20 | 21 | @CreationTimestamp 22 | @Column 23 | private LocalDateTime createdAt; 24 | 25 | @UpdateTimestamp 26 | @Column 27 | private LocalDateTime updatedAt; 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public LocalDateTime getCreatedAt() { 34 | return createdAt; 35 | } 36 | 37 | public LocalDateTime getUpdatedAt() { 38 | return updatedAt; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /storage/db-core/src/main/java/io/dodn/springboot/storage/db/core/ExampleEntity.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core; 2 | 3 | import jakarta.persistence.Column; 4 | import jakarta.persistence.Entity; 5 | 6 | @Entity 7 | public class ExampleEntity extends BaseEntity { 8 | 9 | @Column 10 | private String exampleColumn; 11 | 12 | public ExampleEntity() { 13 | } 14 | 15 | public ExampleEntity(String exampleColumn) { 16 | this.exampleColumn = exampleColumn; 17 | } 18 | 19 | public String getExampleColumn() { 20 | return exampleColumn; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /storage/db-core/src/main/java/io/dodn/springboot/storage/db/core/ExampleRepository.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | public interface ExampleRepository extends JpaRepository { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /storage/db-core/src/main/java/io/dodn/springboot/storage/db/core/config/CoreDataSourceConfig.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core.config; 2 | 3 | import com.zaxxer.hikari.HikariConfig; 4 | import com.zaxxer.hikari.HikariDataSource; 5 | 6 | import org.springframework.beans.factory.annotation.Qualifier; 7 | import org.springframework.boot.context.properties.ConfigurationProperties; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | @Configuration 12 | class CoreDataSourceConfig { 13 | 14 | @Bean 15 | @ConfigurationProperties(prefix = "storage.datasource.core") 16 | public HikariConfig coreHikariConfig() { 17 | return new HikariConfig(); 18 | } 19 | 20 | @Bean 21 | public HikariDataSource coreDataSource(@Qualifier("coreHikariConfig") HikariConfig config) { 22 | return new HikariDataSource(config); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /storage/db-core/src/main/java/io/dodn/springboot/storage/db/core/config/CoreJpaConfig.java: -------------------------------------------------------------------------------- 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 | class CoreJpaConfig { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /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/java/io/dodn/springboot/storage/db/CoreDbContextTest.java: -------------------------------------------------------------------------------- 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 | public abstract class CoreDbContextTest { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /storage/db-core/src/test/java/io/dodn/springboot/storage/db/CoreDbTestApplication.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan; 6 | 7 | @ConfigurationPropertiesScan 8 | @SpringBootApplication 9 | public class CoreDbTestApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(CoreDbTestApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /storage/db-core/src/test/java/io/dodn/springboot/storage/db/core/ExampleRepositoryIT.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.storage.db.core; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import io.dodn.springboot.storage.db.CoreDbContextTest; 6 | 7 | import org.junit.jupiter.api.Test; 8 | 9 | public class ExampleRepositoryIT extends CoreDbContextTest { 10 | 11 | private final ExampleRepository exampleRepository; 12 | 13 | public ExampleRepositoryIT(ExampleRepository exampleRepository) { 14 | this.exampleRepository = exampleRepository; 15 | } 16 | 17 | @Test 18 | public void testShouldBeSavedAndFound() { 19 | ExampleEntity saved = exampleRepository.save(new ExampleEntity("SPRING_BOOT")); 20 | assertThat(saved.getExampleColumn()).isEqualTo("SPRING_BOOT"); 21 | 22 | ExampleEntity found = exampleRepository.findById(saved.getId()).get(); 23 | assertThat(found.getExampleColumn()).isEqualTo("SPRING_BOOT"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /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: -------------------------------------------------------------------------------- 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: -------------------------------------------------------------------------------- 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: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compileOnly 'jakarta.servlet:jakarta.servlet-api' 3 | compileOnly 'org.springframework.boot:spring-boot-starter-test' 4 | compileOnly 'com.fasterxml.jackson.core:jackson-databind' 5 | api 'org.springframework.restdocs:spring-restdocs-mockmvc' 6 | api 'org.springframework.restdocs:spring-restdocs-restassured' 7 | api 'io.rest-assured:spring-mock-mvc' 8 | } 9 | -------------------------------------------------------------------------------- /tests/api-docs/src/main/java/io/dodn/springboot/test/api/RestDocsTest.java: -------------------------------------------------------------------------------- 1 | package io.dodn.springboot.test.api; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.SerializationFeature; 5 | 6 | import io.restassured.module.mockmvc.RestAssuredMockMvc; 7 | import io.restassured.module.mockmvc.specification.MockMvcRequestSpecification; 8 | 9 | import org.junit.jupiter.api.BeforeEach; 10 | import org.junit.jupiter.api.Tag; 11 | import org.junit.jupiter.api.extension.ExtendWith; 12 | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; 13 | import org.springframework.restdocs.RestDocumentationContextProvider; 14 | import org.springframework.restdocs.RestDocumentationExtension; 15 | import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; 16 | import org.springframework.test.web.servlet.MockMvc; 17 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 18 | 19 | @Tag("restdocs") 20 | @ExtendWith(RestDocumentationExtension.class) 21 | public abstract class RestDocsTest { 22 | 23 | protected MockMvcRequestSpecification mockMvc; 24 | 25 | private RestDocumentationContextProvider restDocumentation; 26 | 27 | @BeforeEach 28 | public void setUp(RestDocumentationContextProvider restDocumentation) { 29 | this.restDocumentation = restDocumentation; 30 | } 31 | 32 | protected MockMvcRequestSpecification given() { 33 | return mockMvc; 34 | } 35 | 36 | protected MockMvcRequestSpecification mockController(Object controller) { 37 | MockMvc mockMvc = createMockMvc(controller); 38 | return RestAssuredMockMvc.given().mockMvc(mockMvc); 39 | } 40 | 41 | private MockMvc createMockMvc(Object controller) { 42 | MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper()); 43 | 44 | return MockMvcBuilders.standaloneSetup(controller) 45 | .apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation)) 46 | .setMessageConverters(converter) 47 | .build(); 48 | } 49 | 50 | private ObjectMapper objectMapper() { 51 | return new ObjectMapper().findAndRegisterModules() 52 | .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) 53 | .disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /tests/api-docs/src/main/java/io/dodn/springboot/test/api/RestDocsUtils.java: -------------------------------------------------------------------------------- 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 | public class RestDocsUtils { 8 | 9 | public static OperationRequestPreprocessor requestPreprocessor() { 10 | return Preprocessors.preprocessRequest( 11 | Preprocessors.modifyUris().scheme("http").host("dev.dodn.io").removePort(), 12 | Preprocessors.prettyPrint()); 13 | } 14 | 15 | public static OperationResponsePreprocessor responsePreprocessor() { 16 | return Preprocessors.preprocessResponse(Preprocessors.prettyPrint()); 17 | } 18 | 19 | } 20 | --------------------------------------------------------------------------------