Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FunctionTypeUtils for FactoryBean #1224

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,6 +78,7 @@
*
* @author Oleg Zhurakousky
* @author Andrey Shlykov
* @author Artem Bilan
*
* @since 3.0
*/
Expand Down Expand Up @@ -444,6 +445,12 @@ else if (!(type instanceof ParameterizedType)) {
}
}
}
else if (type instanceof ParameterizedType) {
ResolvableType resolvableType = ResolvableType.forType(type);
if (FactoryBean.class.isAssignableFrom(resolvableType.toClass())) {
return resolvableType.getGeneric(0).getType();
}
}
return type;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,7 @@
import reactor.util.function.Tuple3;
import reactor.util.function.Tuples;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand Down Expand Up @@ -83,6 +84,7 @@
/**
*
* @author Oleg Zhurakousky
* @author Artem Bilan
*
*/
public class BeanFactoryAwareFunctionRegistryTests {
Expand Down Expand Up @@ -849,6 +851,14 @@ public void testArrayPayloadOnFluxFunction() throws Exception {
assertThat(result.size()).isEqualTo(3);
}

@Test
void functionFromFactoryBeanIsProperlyResolved() {
FunctionCatalog catalog = configureCatalog();
Function<Number, String> numberToStringFactoryBean = catalog.lookup("numberToStringFactoryBean");
assertThat(numberToStringFactoryBean).isNotNull();
assertThat(numberToStringFactoryBean.apply(1)).isEqualTo("1");
}

@Test
// see GH-707
public void testConcurrencyOnLookup() throws Exception {
Expand Down Expand Up @@ -1300,6 +1310,23 @@ public Consumer<Flux<String>> reactiveConsumer() {
public Consumer<Flux<Person>> reactivePojoConsumer() {
return flux -> flux.subscribe(v -> consumerInputRef.set(v));
}

@Bean
FactoryBean<Function<Number, String>> numberToStringFactoryBean() {
return new FactoryBean<>() {

@Override
public Function<Number, String> getObject() {
return Number::toString;
}

@Override
public Class<?> getObjectType() {
return Function.class;
}

};
}
}

@EnableAutoConfiguration
Expand Down
Loading