Skip to content

Commit 08d8fe2

Browse files
init commit with r2dbc service template
1 parent 1dfb42d commit 08d8fe2

39 files changed

+746
-641
lines changed

.github/workflows/build-and-upload.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
context: .
8080
push: true
8181
platforms: linux/amd64, linux/arm64
82-
tags: xcodeassociated/spring-mvc-jpa-template:latest
82+
tags: xcodeassociated/spring-reactive-r2dbc-template:latest
8383

8484
dependency-submission:
8585
runs-on: ubuntu-latest

build.gradle

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ plugins {
55
id 'io.spring.dependency-management' version '1.1.6'
66
id 'org.jetbrains.kotlin.jvm' version '2.0.20'
77
id 'org.jetbrains.kotlin.plugin.spring' version '2.0.20'
8-
id 'org.jetbrains.kotlin.plugin.jpa' version '2.0.20'
9-
id "org.jetbrains.kotlin.kapt" version "2.0.20"
108
id "org.liquibase.gradle" version "2.2.1"
119
id "com.google.osdetector" version "1.7.3"
1210
id 'groovy'
@@ -27,23 +25,30 @@ repositories {
2725
}
2826

2927
ext {
28+
set('springCloudVersion', '2023.0.3')
3029
set('testcontainersVersion', '1.20.1')
3130
}
3231

3332
dependencies {
34-
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
35-
implementation 'org.springframework.boot:spring-boot-starter-web'
33+
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
34+
implementation 'org.springframework.boot:spring-boot-starter-webflux'
35+
implementation 'org.springframework:spring-jdbc'
36+
runtimeOnly 'org.postgresql:r2dbc-postgresql'
37+
runtimeOnly 'org.postgresql:postgresql'
38+
implementation 'io.projectreactor.kotlin:reactor-kotlin-extensions'
39+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-reactor'
3640
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
3741
implementation 'org.jetbrains.kotlin:kotlin-reflect'
3842
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
3943
implementation 'org.springframework.boot:spring-boot-starter-validation'
4044
developmentOnly 'org.springframework.boot:spring-boot-devtools'
41-
runtimeOnly 'org.postgresql:postgresql'
45+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-slf4j'
4246
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
4347
testImplementation 'org.springframework.boot:spring-boot-starter-test'
4448

4549
// test utils
4650
testImplementation 'io.projectreactor:reactor-test'
51+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test'
4752
testImplementation 'io.mockk:mockk:1.13.12'
4853
testImplementation 'com.ninja-squad:springmockk:4.0.2'
4954

@@ -60,10 +65,7 @@ dependencies {
6065
// testcontainers
6166
testImplementation 'org.testcontainers:junit-jupiter'
6267
testImplementation 'org.testcontainers:postgresql'
63-
64-
// guerydsl
65-
implementation 'com.querydsl:querydsl-jpa:5.1.0'
66-
kapt group: 'com.querydsl', name: 'querydsl-apt', version: '5.1.0', classifier: 'jakarta'
68+
testImplementation 'org.testcontainers:r2dbc'
6769

6870
// liquibase
6971
implementation ('org.liquibase:liquibase-core:4.29.2') {
@@ -72,27 +74,27 @@ dependencies {
7274
}
7375
liquibaseRuntime 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
7476
liquibaseRuntime 'org.jetbrains.kotlin:kotlin-reflect'
75-
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate6:4.29.2'
77+
liquibaseRuntime 'org.liquibase.ext:liquibase-postgresql:4.29.2'
7678
liquibaseRuntime 'org.postgresql:postgresql:42.7.4'
7779
liquibaseRuntime 'ch.qos.logback:logback-core:1.5.8'
7880
liquibaseRuntime 'ch.qos.logback:logback-classic:1.5.8'
7981
liquibaseRuntime 'info.picocli:picocli:4.7.6'
80-
liquibaseRuntime "org.springframework.boot:spring-boot-starter-data-jpa:3.3.1"
82+
liquibaseRuntime "org.springframework.boot:spring-boot-starter-data-r2dbc:3.3.3"
8183
liquibaseRuntime sourceSets.main.output
8284

8385
// spring security
84-
implementation 'org.springframework.boot:spring-boot-starter-webflux'
8586
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
8687
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
8788
implementation 'org.springframework.boot:spring-boot-starter-security'
8889
testImplementation 'org.springframework.security:spring-security-test'
8990

9091
// kafka
9192
implementation 'org.springframework.kafka:spring-kafka'
93+
implementation 'io.projectreactor.kafka:reactor-kafka'
9294
testImplementation 'org.springframework.kafka:spring-kafka-test'
9395

9496
// circuit breaker
95-
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j:3.1.2'
97+
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-reactor-resilience4j'
9698

9799
// macOs ARM only
98100
if (osdetector.classifier == "osx-aarch_64") {
@@ -109,22 +111,22 @@ dependencies {
109111
implementation 'io.zipkin.reporter2:zipkin-sender-urlconnection'
110112

111113
}
114+
112115
liquibase {
113116
activities {
114117
main {
115-
changeLogFile "$projectDir/src/main/resources/db/changesets/changelog.yml"
118+
changeLogFile "src/main/resources/db/db.changelog.yml"
116119
url "jdbc:postgresql://localhost:5432/application"
117120
username "admin"
118121
password "admin"
119122
driver 'org.postgresql.Driver'
120-
referenceUrl 'hibernate:spring:com.softeno.template?dialect=org.hibernate.dialect.PostgreSQL95Dialect&hibernate.use_jdbc_metadata_defaults=true&hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
121-
referenceDriver 'liquibase.ext.hibernate.database.connection.HibernateDriver'
122123
}
123124
}
124125
}
125126

126127
dependencyManagement {
127128
imports {
129+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
128130
mavenBom "org.testcontainers:testcontainers-bom:${testcontainersVersion}"
129131
}
130132
}

docker/postgres/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
postgres:
4-
image: postgres:15.2-alpine
4+
image: postgres:16-alpine
55
volumes:
66
- postgres-data:/var/lib/postgresql/data
77
environment:

http/user-app.http

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Permissions
22

33
###
4-
GET {{host}}/permissions?page=0&size=10&sort=id&direction=DESC
4+
GET {{host}}/permissions?page=0&size=10&sort=id&direction=ASC
55
Authorization: Bearer {{oauthToken}}
66

77
###
@@ -20,7 +20,7 @@ GET {{host}}/permissions/{{permissionId}}
2020
Authorization: Bearer {{oauthToken}}
2121

2222
###
23-
PUT {{host}}/permissions/{{permissionId}}
23+
PUT {{host}}/permissions/5
2424
Content-Type: application/json
2525
Authorization: Bearer {{oauthToken}}
2626

src/main/kotlin/com/softeno/template/SoftenoMvcJpaApp.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
44
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
55
import org.springframework.boot.context.properties.EnableConfigurationProperties
66
import org.springframework.boot.runApplication
7-
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
7+
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories
88
import org.springframework.transaction.annotation.EnableTransactionManagement
9+
import reactor.core.publisher.Hooks
910

1011
@SpringBootApplication
11-
@EnableJpaRepositories
1212
@EnableTransactionManagement
1313
@EnableConfigurationProperties
14+
@EnableR2dbcRepositories
1415
@ConfigurationPropertiesScan("com.softeno")
1516
class SoftenoMvcJpaApp
1617

1718
fun main(args: Array<String>) {
19+
Hooks.enableAutomaticContextPropagation()
1820
runApplication<SoftenoMvcJpaApp>(*args)
1921
}
2022

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.softeno.template.app.common
2+
3+
//import io.micrometer.tracing.Tracer
4+
import kotlinx.coroutines.reactor.awaitSingleOrNull
5+
import org.apache.commons.logging.Log
6+
import org.springframework.security.core.context.ReactiveSecurityContextHolder
7+
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken
8+
import reactor.core.publisher.Mono
9+
import java.security.Principal
10+
11+
interface PrincipalHandler {
12+
suspend fun showPrincipal(log: Log, monoPrincipal: Mono<Principal>){
13+
val principal = monoPrincipal.awaitSingleOrNull()
14+
log.info("principal: $principal, name: ${principal?.name}")
15+
val authentication = ReactiveSecurityContextHolder.getContext().map { it.authentication }.awaitSingleOrNull()
16+
if (authentication != null) {
17+
val token = (authentication as JwtAuthenticationToken).token
18+
val userId = token.claims["sub"]
19+
val authorities = authentication.authorities
20+
log.debug("authentication: $authentication")
21+
log.debug("authorities: $authorities")
22+
log.debug("token: $token")
23+
log.debug("token claims: ${token.claims}")
24+
log.info("keycloak userId: $userId")
25+
}
26+
}
27+
}

src/main/kotlin/com/softeno/template/app/common/api/config/GlobalExceptionHandler.kt

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/kotlin/com/softeno/template/app/common/db/BaseEntity.kt

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/main/kotlin/com/softeno/template/app/common/error/ErrorType.kt

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/kotlin/com/softeno/template/app/common/events/AppEvent.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)