Daniel Czosnek opened SPR-17252 and commented
I have a simple config class:
@Configuration
public class Config {
@Bean
public String string(@Qualifier("testyTest") Object[] objects){
return Arrays.toString(objects);
}
@Bean
public Object[] testyTest() {
return null;
}
}
And a class that uses this config:
public class Test {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
Object[] o = context.getBean(Object[].class);
System.out.println(Arrays.toString(o));
String s = context.getBean(String.class);
System.out.println(s);
}
}
The String
being printed is different from the Object[]
:
[]
[[Ljava.lang.Object;@1283bb96]
It turns out, that the @Bean
that returns String is receiving an Object[1][] array which has an Object[0] array as its sole element (despite using @Qualifier
). However, context.getBean(Object[].class)
returns Object[0]
correctly.
Affects: 5.0.8
Comment From: snicoll
You're asking to inject all the beans of type object matching the qualifier. There's only one, so the context injects an array of the single object matching the qualifier. Exposing bean of type array or list can be confusing, I'd recommend using a dedicated type for this.