Affects: 6.2.0-SNAPSHOT. It starts on 6.2.0-M1
Let's start with a MRE:
package com.example.demo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
class Demo {
public static void main(String[] args) {
var context = new AnnotationConfigApplicationContext();
context.registerBean("genericBean", GenericClass.class, GenericClass::new);
context.registerBean("objectGenericConsumer", ObjectConsumer.class);
context.registerBean("arrayGenericConsumer", ArrayConsumer.class); // This is the problematic line
context.refresh();
}
}
class GenericClass<T> {}
record ObjectConsumer(GenericClass<Object> genericClass) {}
record ArrayConsumer(GenericClass<byte[]> genericClass) {}
Here a bean is registered as GenericClass<?>
. Later it is autowired as a dependency of other beans. It works when a dependency is defined as GenericClass<Object>
but doesn't work for arrays. I'm using byte[]
as an example, but any array won't work including Object
arrays. I suppose it's a bug as this example works on earlier versions.
An example when it might be important
Spring boot registers KafkaTemplate<?,?>
bean as it can be seen in KafkaAutoConfiguration. When used it's declared with concrete generic parameters defined by used key and value serializers. Value serializer org.apache.kafka.common.serialization.ByteArraySerializer
works with byte arrays, so requires the second generic parameter to be byte[]
.