Skip to content

Failed to load ApplicationContext in kotlin when using inner class @Component inside @Configuration #22721

@anton-kapelyushok

Description

@anton-kapelyushok

kotlinVersion = "1.3.21"
springBootVersion = '2.1.3.RELEASE'

Following code throws an exception breaking context setup:

import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.SpringBootConfiguration
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.ComponentScan
import org.springframework.stereotype.Component

@SpringBootConfiguration
@ComponentScan
class MyConfig{
    @Component
    inner class BeanB {
        fun print() {
            println("beanB")
        }
    }
}

@SpringBootTest
class KotlinTest {
    @Autowired
    lateinit var beanB: MyConfig.BeanB

    @Test
    fun a() {
        beanB.print()
    }
}

The error is:

Error creating bean with name kotlin.MyConfig$BeanB'
...
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:705)

When translating and running the snippet on Java everything works as expected.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: invalidAn issue that we don't feel is validtheme: 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