Use Kotlin String Templates

See gh-42801
This commit is contained in:
jeonghyeon00
2024-10-21 13:06:00 +09:00
committed by Stéphane Nicoll
parent a3c34b4936
commit 35b19008e6

View File

@@ -55,14 +55,14 @@ inline fun <reified T : Any> runApplication(vararg args: String, init: SpringApp
*/
inline fun <reified T : Any> fromApplication(): SpringApplication.Augmented {
val type = T::class
val ktClassName = type.qualifiedName + "Kt"
val ktClassName = "${type.qualifiedName}Kt"
try {
val ktClass = ClassUtils.resolveClassName(ktClassName, type.java.classLoader)
val mainMethod = ReflectionUtils.findMethod(ktClass, "main", Array<String>::class.java)
Assert.notNull(mainMethod, "Unable to find main method")
return SpringApplication.from { ReflectionUtils.invokeMethod(mainMethod!!, null, it) }
} catch (ex: Exception) {
throw IllegalStateException("Unable to use 'fromApplication' with " + type.qualifiedName)
throw IllegalStateException("Unable to use 'fromApplication' with ${type.qualifiedName}")
}
}