Skip to content

List of bean by types autowiring in Kotlin AOT not working since 6.2.0 #34122

@artemptushkin

Description

@artemptushkin

I have Spring Boot 3.4.0 project that uses Spring Boot AOT plugin org.springframework.boot.aot so the Java runtime runs with -Dspring.aot.enabled=true. I don't use Spring GraalVM native, so it's only AOT.

I have the following Kotlin code:

@Configuration
class TelegramCommandsConfiguration(
    private val commandsBeans: List<TelegramCommand>,
    private val callbackBeans: List<TelegramCallbackHandler>,
) {

    @Bean
    fun commands(): Map<String, TelegramCommand> = commandsBeans.associateBy { it.name() } // returns 0

    @Bean
    fun callbacks(): Map<String, TelegramCallbackHandler> = callbackBeans.associateBy { it.name() } // returns 0
}

Where:

  • TelegramCommand is an interface
  • there are N beans of it, some defined with @Bean and some defined with @Component
  • Being on SB 3.3.6 and Spring 6.1.15 all are fetched as expected with the List access.
image

But since I updated SB to 3.4.0 and made no other changes to the list variables, I fetched 0 beans by the interface TelegramCommand.

image

I read about the recent changes in core container but I can not find a clue about what I should do now.

Is this an issue?


I tried to run w/o AOT - all good the beans of TelegramCommand are there so it's something about AOT.


Workaround, explicit access:

@Bean
    fun commands(): Commands = Commands(
        applicationContext.getBeansOfType<TelegramCommand>(TelegramCommand::class.java)
            .entries
            .associateBy({ it.value.name() }, { it.value })
    )

Metadata

Metadata

Assignees

Labels

status: duplicateA duplicate of another issuetheme: aotAn issue related to Ahead-of-time processingtheme: kotlinAn issue related to Kotlin support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions