Skip to content

Commit b95085f

Browse files
committed
add support for spring-boot 4x #480
1 parent a9d2560 commit b95085f

File tree

8 files changed

+147
-6
lines changed

8 files changed

+147
-6
lines changed

gradle/libs.versions.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
kotlin = "2.2.10"
33
kotlinx = "1.10.2"
44
kotest = "6.0.5"
5-
detekt = "1.23.8"
65
junit = "5.14.1"
76
koin = "4.1.1"
87
quarkus = "3.30.0"
98
jakarta = "4.1.0"
109
spring-boot-2x = "2.7.18"
1110
spring-boot-3x = "3.5.8"
11+
spring-boot-4x = "4.0.0"
1212
ktlint = "1.8.0"
1313

1414
[libraries]
@@ -20,8 +20,10 @@ quarkusBom = { module = "io.quarkus:quarkus-bom", version.ref = "quarkus" }
2020
quarkus-arc = { module = "io.quarkus:quarkus-arc", version.ref = "quarkus" }
2121
jakarta-enterpise-cdi-api = { module = "jakarta.enterprise:jakarta.enterprise.cdi-api", version.ref = "jakarta" }
2222

23+
spring-boot-4x-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "spring-boot-4x" }
24+
spring-boot-4x-starter-test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "spring-boot-4x" }
25+
2326
spring-boot-3x-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "spring-boot-3x" }
24-
spring-boot-3x-autoconfigure = { module = "org.springframework.boot:spring-boot-autoconfigure", version.ref = "spring-boot-3x" }
2527
spring-boot-3x-starter-test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "spring-boot-3x" }
2628

2729
spring-boot-2x-starter = { module = "org.springframework.boot:spring-boot-starter", version.ref = "spring-boot-2x" }
@@ -30,20 +32,17 @@ ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint
3032

3133
# test
3234
kotest-runner-junit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
33-
kotest-assertions-arrow = { module = "io.kotest.extensions:kotest-assertions-arrow", version = "2.0.0" }
3435
kotest-framework-engine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
3536
kotest-assertions-core = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
3637
kotest-assertions-table = { module = "io.kotest:kotest-assertions-table", version.ref = "kotest" }
3738
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx" }
3839
koin-test = { module = "io.insert-koin:koin-test", version.ref = "koin" }
3940
koin-test-junit5 = { module = "io.insert-koin:koin-test-junit5", version.ref = "koin" }
4041
quarkus-junit5 = { module = "io.quarkus:quarkus-junit5", version.ref = "quarkus" }
41-
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" }
4242

4343
[plugins]
4444
kover = { id = "org.jetbrains.kotlinx.kover", version = "0.9.3" }
4545
testLogger = { id = "com.adarshr.test-logger", version = "4.0.0" }
46-
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
4746
spotless = { id = "com.diffplug.spotless", version = "8.1.0" }
4847
quarkus = { id = "io.quarkus", version.ref = "quarkus" }
4948
maven-publish = { id = "com.vanniktech.maven.publish", version = "0.35.0" }

projects/kediatr-spring-boot-3x-starter/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
dependencies {
22
api(projects.projects.kediatrCore)
33
implementation(libs.spring.boot.get3x().starter)
4-
implementation(libs.spring.boot.get3x().autoconfigure)
54
}
65

76
dependencies {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dependencies {
2+
api(projects.projects.kediatrCore)
3+
implementation(libs.spring.boot.get4x().starter)
4+
}
5+
6+
dependencies {
7+
testImplementation(testFixtures(projects.projects.kediatrCore))
8+
testImplementation(libs.spring.boot.get4x().starter.test)
9+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.trendyol.kediatr.spring
2+
3+
import com.trendyol.kediatr.Mediator
4+
import org.springframework.boot.autoconfigure.AutoConfiguration
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
6+
import org.springframework.context.ApplicationContext
7+
import org.springframework.context.annotation.Bean
8+
9+
@AutoConfiguration
10+
open class KediatRAutoConfiguration {
11+
@Bean
12+
@ConditionalOnMissingBean
13+
open fun kediatRSpringBeanProvider(
14+
applicationContext: ApplicationContext
15+
): KediatRSpringBeanProvider = KediatRSpringBeanProvider(applicationContext)
16+
17+
@Bean
18+
@ConditionalOnMissingBean
19+
open fun mediator(
20+
kediatRSpringBeanProvider: KediatRSpringBeanProvider
21+
): Mediator = Mediator.build(kediatRSpringBeanProvider)
22+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@file:Suppress("UNCHECKED_CAST")
2+
3+
package com.trendyol.kediatr.spring
4+
5+
import com.trendyol.kediatr.DependencyProvider
6+
import org.springframework.context.ApplicationContext
7+
8+
class KediatRSpringBeanProvider(
9+
private val applicationContext: ApplicationContext
10+
) : DependencyProvider {
11+
override fun <T> getSingleInstanceOf(clazz: Class<T>): T = applicationContext
12+
.getBeanNamesForType(clazz)
13+
.single()
14+
.let { applicationContext.getBean(it) as T }
15+
16+
override fun <T> getSubTypesOf(
17+
clazz: Class<T>
18+
): Collection<Class<T>> = applicationContext
19+
.getBeanNamesForType(clazz)
20+
.map { applicationContext.getType(it) as Class<T> }
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.trendyol.kediatr.spring.KediatRAutoConfiguration
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.trendyol.kediatr.spring
2+
3+
import com.trendyol.kediatr.Mediator
4+
import com.trendyol.kediatr.testing.*
5+
import org.springframework.beans.factory.annotation.Autowired
6+
import org.springframework.boot.test.context.SpringBootTest
7+
import org.springframework.context.annotation.*
8+
9+
@SpringBootTest(
10+
classes = [
11+
KediatRAutoConfiguration::class,
12+
MediatorTests.TestConfiguration::class,
13+
TestRequestHandler::class,
14+
ExceptionPipelineBehavior::class,
15+
LoggingPipelineBehavior::class,
16+
TestQueryHandler::class,
17+
TestNotificationHandler::class,
18+
TestBrokenRequestHandler::class,
19+
TestPipelineRequestHandler::class,
20+
TestCommandWithResultRequestHandler::class,
21+
TestInheritedRequestHandlerForSpecificCommand::class,
22+
TestRequestHandlerWithoutInjection::class,
23+
TestRequestHandlerForTypeLimitedInheritance::class,
24+
ParameterizedRequestHandler::class,
25+
ParameterizedRequestHandlerForInheritance::class,
26+
ParameterizedCommandWithResultHandler::class,
27+
ParameterizedCommandWithResultHandlerOfInheritedHandler::class,
28+
APingHandler::class,
29+
AnotherPingHandler::class,
30+
Handler1ForNotificationOfMultipleHandlers::class,
31+
Handler2ForNotificationOfMultipleHandlers::class,
32+
InheritedNotificationHandler::class,
33+
InheritedNotificationHandler2::class,
34+
ParameterizedNotificationHandler::class,
35+
ParameterizedNotificationHandlerForInheritance::class,
36+
TestPipelineRequestHandlerWithoutInjection::class,
37+
TestPipelineRequestHandlerThatFails::class,
38+
InheritedPipelineBehaviour::class,
39+
ParameterizedQueryHandler::class,
40+
FirstPipelineBehaviour::class,
41+
SecondPipelineBehaviour::class,
42+
ThirdPipelineBehaviour::class,
43+
RequestHandlerThatPassesThroughOrderedPipelineBehaviours::class,
44+
QueryHandlerThatPassesThroughOrderedPipelineBehaviours::class,
45+
NotificationHandlerThatPassesThroughOrderedPipelineBehaviours::class,
46+
TestCommandBaseHandler::class,
47+
TestQueryBaseHandler::class,
48+
TestCommandWithResultBaseHandler::class,
49+
TestCommandForInheritanceWithFallbackHandlerHandler::class,
50+
TestRequestHandlerForCommandInherited2::class,
51+
ModifyingPipelineBehavior::class,
52+
TimingPipelineBehavior::class,
53+
ConditionalPipelineBehavior::class,
54+
RequestWithNullableResultHandler::class,
55+
RequestWithNullParameterHandler::class,
56+
NestedGenericRequestHandler::class,
57+
WildcardGenericRequestHandler::class,
58+
ConcurrentRequestHandler::class,
59+
LongRunningRequestHandler::class,
60+
MultiInterfaceRequestHandler::class,
61+
EmptyRequestHandler::class,
62+
VoidResultRequestHandler::class,
63+
CollectionRequestHandler::class,
64+
RequestThatThrowsSpecificExceptionHandler::class,
65+
RequestThatThrowsRuntimeExceptionHandler::class,
66+
ComplexPipelineRequestHandler::class,
67+
ComplexDataRequestHandler::class,
68+
NotificationThatThrowsExceptionHandler1::class,
69+
NotificationThatThrowsExceptionHandler2::class,
70+
NotificationThatThrowsExceptionHandler3::class,
71+
SlowNotificationHandler1::class,
72+
SlowNotificationHandler2::class,
73+
SlowNotificationHandler3::class,
74+
SelfReferencingRequestHandler::class,
75+
CatchAllNotificationsHandler::class
76+
]
77+
)
78+
class MediatorTests : MediatorUseCases() {
79+
@Autowired
80+
lateinit var mediator: Mediator
81+
82+
override fun provideMediator(): Mediator = mediator
83+
84+
@Configuration
85+
open class TestConfiguration {
86+
@Bean
87+
open fun mediatorAccessor(mediator: Mediator): MediatorAccessor = { mediator }
88+
}
89+
}

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ include(
1010
"projects:kediatr-quarkus-starter",
1111
"projects:kediatr-spring-boot-2x-starter",
1212
"projects:kediatr-spring-boot-3x-starter",
13+
"projects:kediatr-spring-boot-4x-starter",
1314
)
1415

1516
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

0 commit comments

Comments
 (0)