I'm trying to get Spring Boot dependency injection to allow me to do the following:
interface MyBean
@Component
class MyBeanA : MyBean
@Component
class MyBeanB : MyBean
@Component
class MyBeanConsumer(myBean: MyBean)
Here, Spring complains that there are multiple beans of type MyBean
. I would like it to create two instances of MyBeanConsumer
. One with MyBeanA
and one with MyBeanB
. I need to do this for a number of beans, so I'm trying to avoid boilerplate configuration classes like this:
@Configuration
class MyBeanConfiguration {
@Bean
fun consumers(myBeans: List<MyBean>) = myBeans.map { MyBeanConsumer(it) }
}
Is this possible in Spring?