Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeHintRegistrar error bean registration #30382

Closed
Kotlin-GDE opened this issue Apr 26, 2023 · 5 comments
Closed

RuntimeHintRegistrar error bean registration #30382

Kotlin-GDE opened this issue Apr 26, 2023 · 5 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue theme: aot An issue related to Ahead-of-time processing

Comments

@Kotlin-GDE
Copy link

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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 26, 2023
@bclozel
Copy link
Member

bclozel commented Apr 26, 2023

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?

@bclozel bclozel added status: waiting-for-feedback We need additional information before we can continue theme: aot An issue related to Ahead-of-time processing in: core Issues in core modules (aop, beans, core, context, expression) labels Apr 26, 2023
@Kotlin-GDE
Copy link
Author

Kotlin-GDE commented Apr 26, 2023

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

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 26, 2023
@snicoll
Copy link
Member

snicoll commented Apr 26, 2023

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.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Apr 26, 2023
@mmarimuthu
Copy link

How do we fix for a java application. any code samples would help.

@bclozel
Copy link
Member

bclozel commented Apr 4, 2024

The linked reference docs have a few.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue theme: aot An issue related to Ahead-of-time processing
Projects
None yet
Development

No branches or pull requests

5 participants