hi,
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.6)
2023-04-26T10:11:02.074+01:00 INFO 5647 --- [ main] d.halim.springboot.SpringApplicationKt : Starting SpringApplicationKt using Java 19.0.1 with PID 5647 (/home/halim/Software/My Projects/springboot/build/classes/kotlin/main started by halim in /home/halim/Software/My Projects/springboot)
2023-04-26T10:11:02.078+01:00 INFO 5647 --- [ main] d.halim.springboot.SpringApplicationKt : No active profile set, falling back to 1 default profile: "default"
2023-04-26T10:11:03.842+01:00 INFO 5647 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
2023-04-26T10:11:03.877+01:00 INFO 5647 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 27 ms. Found 0 R2DBC repository interfaces.
Exception in thread "main" java.lang.IllegalArgumentException: Code generation is not supported for bean definitions declaring an instance supplier callback : Root bean: class [org.springframework.aot.hint.RuntimeHintsRegistrar]; scope=singleton; abstract=false; lazyInit=true; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null
Comment From: bclozel
This is due to an intentional change in Spring Framework 6.0.5
, see #29556. We're planning on improving the situation with #29555. I'm surprised you're getting this error for RuntimeHintsRegistrar
. Could you share a sample application?
Comment From: Kotlin-GDE
i use spring 6.0.8, boot 3.0.6, kotin 1.8.20, java 19.0.1
data class Person(val id: Int, val name: String)
fun main() {
runApplication<SpringApplication>() {
addInitializers(beans {
bean<RuntimeHintsRegistrar> {
RuntimeHintsRegistrar { hints, _ ->
hints.reflection().registerType(Person::class.java, MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_METHODS)
}
}
})
}
}
@SpringBootApplication
class SpringApplication {
@Bean
fun router() = coRouter {
val stream = flow {
emit(Person(1, "a"))
emit(Person(2, "b"))
emit(Person(3, "c"))
}.onEach { delay(300) }
GET("/") { ok().bodyValueAndAwait("hi") }
GET("/flow/json") { ok().contentType(MediaType.APPLICATION_NDJSON).bodyAndAwait(stream) }
}
}
when try to generate native executable with gradle (gradle nativeCompile) exception appear
Comment From: snicoll
Looking at your code, it's obvious that the RuntimeHintsRegistrar
bean should be ignored. However, defining the registrar as a bean is not supported. We try as much as possible to make sure that components that need to be instantiated at build time are separate. Only bean factory processing-related contracts are instantiated.
See the reference guide for the recommended approaches. Please use @ImportRuntimeHints
, typically on your router
function.
Comment From: mmarimuthu
How do we fix for a java application. any code samples would help.
Comment From: bclozel
The linked reference docs have a few.