-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Open
Labels
type: wiki-documentationA documentation update required on the wikiA documentation update required on the wiki
Description
Hello,
I saw the different issues #45938 and #45709
The issue here is different from those. I set up a really stupid example that is not our use-case, but it illustrates the goal.
Consider a class GenericClass<T>
.
Working in 3.4.6 :
@Bean
public GenericClass<String> genericBean1() {
return new GenericClass<>("Hello, Generics!");
}
@Bean
@ConditionalOnMissingBean
public GenericClass<Integer> genericBean2() {
return new GenericClass<>(7);
}
@Bean
public CommandLineRunner init(GenericClass<?> genericBean) {
return args -> System.out.println("GenericClass with value: " + genericBean.getValue());
}
Starting from 3.5.0 :
Parameter 0 of method init in com.example.generics.demo.DemoApplication required a single bean, but 2 were found:
- genericBean1: defined by method 'genericBean1' in class path resource [com/example/generics/demo/DemoConfiguration.class]
- genericBean2: defined by method 'genericBean2' in class path resource [com/example/generics/demo/DemoConfiguration2.class]
The only "workaround" in 3.5+ is to change the bean definitions with the wildcard ?
instead of the concrete type.
For example :
@Bean
@ConditionalOnMissingBean
public GenericClass<?> genericBean2() {
return new GenericClass<>(7);
}
I have not seen anything regarding this in the changelog.
Is it still possible to define @ConditionalOnMissingBean
with a type that uses Generics where the concrete type used in the generic might defer ?
Metadata
Metadata
Assignees
Labels
type: wiki-documentationA documentation update required on the wikiA documentation update required on the wiki