Ensure a concrete type with parametrric subtype is detected
If user defines their own @Beans from conrete types that implement Function<...> then their type signature is detectable from the class.
This commit is contained in:
@@ -494,9 +494,14 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
int index = paramType.isOutput() ? 1 : 0;
|
||||
if (source instanceof StandardMethodMetadata) {
|
||||
// Standard @Bean metadata
|
||||
ParameterizedType type = (ParameterizedType) ((StandardMethodMetadata) source)
|
||||
Type beanType = ((StandardMethodMetadata) source)
|
||||
.getIntrospectedMethod().getGenericReturnType();
|
||||
if (beanType instanceof ParameterizedType) {
|
||||
ParameterizedType type = (ParameterizedType) beanType;
|
||||
param = extractType(type, paramType, index);
|
||||
} else {
|
||||
param = findTypeFromBeanClass((Class<?>) beanType, paramType);
|
||||
}
|
||||
}
|
||||
else if (source instanceof MethodMetadataReadingVisitor) {
|
||||
// A component scan with @Beans
|
||||
|
||||
@@ -211,6 +211,17 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
.isAssignableFrom(Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonParametericTypeFunction() {
|
||||
create(NonParametricTypeSingletonConfiguration.class);
|
||||
assertThat(context.getBean("function")).isInstanceOf(Function.class);
|
||||
assertThat(catalog.lookupFunction("function")).isInstanceOf(Function.class);
|
||||
assertThat(inspector.getInputType(catalog.lookupFunction("function")))
|
||||
.isAssignableFrom(Integer.class);
|
||||
assertThat(inspector.getInputWrapper(catalog.lookupFunction("function")))
|
||||
.isAssignableFrom(Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void componentScanBeanFunction() {
|
||||
create(ComponentScanBeanConfiguration.class);
|
||||
@@ -487,6 +498,15 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
protected static class NonParametricTypeSingletonConfiguration {
|
||||
@Bean
|
||||
public SingletonFunction function() {
|
||||
return new SingletonFunction();
|
||||
}
|
||||
}
|
||||
|
||||
protected static class SingletonFunction implements Function<Integer, String> {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user