Add function style bean

This commit is contained in:
Stéphane Nicoll
2024-07-29 09:17:52 +02:00
parent a8be5c09f0
commit 6b2942e1c3
3 changed files with 23 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ plugins {
dependencies {
implementation(enforcedPlatform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
@@ -18,3 +18,7 @@ dependencies {
appTestImplementation(project(":aot-smoke-test-support"))
appTestImplementation("org.awaitility:awaitility:4.2.0")
}
aotSmokeTest {
webApplication = true
}

View File

@@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.aot.smoketest.support.assertj.AssertableOutput;
import org.springframework.aot.smoketest.support.junit.ApplicationTest;
import org.springframework.test.web.reactive.server.WebTestClient;
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,4 +21,14 @@ public class FunctionalApplicationAotTests {
});
}
@Test
void endpointsAreConfigured(WebTestClient client) {
client.get()
.exchange()
.expectStatus()
.isOk()
.expectBody()
.consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("hi!"));
}
}

View File

@@ -4,6 +4,8 @@ import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.support.beans
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.web.reactive.function.server.router
@SpringBootApplication
class FunctionalApplication
@@ -12,10 +14,15 @@ fun main(args: Array<String>) {
runApplication<FunctionalApplication>(*args) {
addInitializers(beans {
bean<Foo>()
bean(::endpoints)
})
}
}
fun endpoints() = router {
GET("/") { ServerResponse.ok().bodyValue("hi!") }
}
class Foo : CommandLineRunner {
override fun run(vararg args: String?) {
println("Hello world!")