Add function style bean
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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!"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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!")
|
||||
|
||||
Reference in New Issue
Block a user