diff --git a/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt b/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt index 5b911a8ee7e..8ad7555de1b 100644 --- a/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt +++ b/spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,11 +68,12 @@ inline fun fromApplication(): SpringApplication.Augmented { } /** - * Extension function that allows `SpringApplication.Augmented.with` to work with Kotlin classes. + * Extension function that allows [SpringApplication.Augmented.with] to work with Kotlin classes. * * @author Phillip Webb + * @author Sebastien Deleuze * @since 3.1.1 */ -fun SpringApplication.Augmented.with(type: KClass<*>): SpringApplication.Augmented { - return this.with(type.java)!! +fun SpringApplication.Augmented.with(vararg types: KClass<*>): SpringApplication.Augmented { + return this.with(*types.map(KClass<*>::java).toTypedArray())!! } diff --git a/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt b/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt index 7810b2eb1a3..e1971aa17e1 100644 --- a/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt +++ b/spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.getBean import org.springframework.boot.kotlinsample.TestKotlinApplication +import org.springframework.boot.web.servlet.mock.MockFilter import org.springframework.boot.web.servlet.server.MockServletWebServerFactory import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -36,7 +37,7 @@ class SpringApplicationExtensionsTests { @Test fun `Kotlin runApplication() top level function`() { val context = runApplication() - assertThat(context).isNotNull + assertThat(context).isNotNull() } @Test @@ -45,7 +46,7 @@ class SpringApplicationExtensionsTests { val context = runApplication { setEnvironment(environment) } - assertThat(context).isNotNull + assertThat(context).isNotNull() assertThat(environment).isEqualTo(context.environment) } @@ -54,7 +55,7 @@ class SpringApplicationExtensionsTests { val context = runApplication("--debug", "spring", "boot") val args = context.getBean() assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot") - assertThat(args.containsOption("debug")).isEqualTo(true) + assertThat(args.containsOption("debug")).isTrue() } @Test @@ -65,14 +66,21 @@ class SpringApplicationExtensionsTests { } val args = context.getBean() assertThat(args.nonOptionArgs.toTypedArray()).containsExactly("spring", "boot") - assertThat(args.containsOption("debug")).isEqualTo(true) + assertThat(args.containsOption("debug")).isTrue() assertThat(environment).isEqualTo(context.environment) } @Test fun `Kotlin fromApplication() top level function`() { val context = fromApplication().with(ExampleWebConfig::class).run().applicationContext - assertThat(context.getBean()).isNotNull + assertThat(context.getBean()).isNotNull() + } + + @Test + fun `Kotlin fromApplication() top level function with multiple sources`() { + val context = fromApplication().with(ExampleWebConfig::class, ExampleFilterConfig::class).run().applicationContext + assertThat(context.getBean()).isNotNull() + assertThat(context.getBean()).isNotNull() } @Test @@ -91,4 +99,14 @@ class SpringApplicationExtensionsTests { } + @Configuration(proxyBeanMethods = false) + internal open class ExampleFilterConfig { + + @Bean + open fun filter(): MockFilter { + return MockFilter() + } + + } + }