Add additional logic to function catalog to help with singletons
A registered singleton doesn't have a BeanDefinition, but it might have a compiled type with enough generic information to pull out the input and output types.
This commit is contained in:
@@ -29,7 +29,10 @@ import java.util.stream.Collectors;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.compiler.CompiledFunctionFactory;
|
||||
@@ -158,6 +161,17 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
.isAssignableFrom(Map.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singletonFunction() {
|
||||
create(SingletonConfiguration.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);
|
||||
@@ -399,6 +413,26 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
protected static class ExternalConfiguration {
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
protected static class SingletonConfiguration implements BeanFactoryPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
||||
throws BeansException {
|
||||
beanFactory.registerSingleton("function", new SingletonFunction());
|
||||
}
|
||||
}
|
||||
|
||||
protected static class SingletonFunction implements Function<Integer, String> {
|
||||
|
||||
@Override
|
||||
public String apply(Integer input) {
|
||||
return "value=" + input;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = GenericFunction.class)
|
||||
|
||||
Reference in New Issue
Block a user