Refactor some lambdas to enable native image building
Without this change a function with a Tomcat wrapper cannot be compiled to a native image (or it can but it fails at runtime) because there are lambda$$$ methods in the byte code that refer to missing types.
This commit is contained in:
@@ -108,8 +108,7 @@ class FunctionEndpointInitializer implements ApplicationContextInitializer<Gener
|
||||
context.registerBean(FunctionEndpointFactory.class,
|
||||
() -> new FunctionEndpointFactory(context.getBean(FunctionCatalog.class),
|
||||
context.getBean(RequestProcessor.class), context.getEnvironment()));
|
||||
context.registerBean(RouterFunction.class,
|
||||
() -> context.getBean(FunctionEndpointFactory.class).functionEndpoints());
|
||||
RouterFunctionRegister.register(context);
|
||||
}
|
||||
|
||||
private HttpWebHandlerAdapter httpHandler(GenericApplicationContext context) {
|
||||
@@ -131,6 +130,15 @@ class FunctionEndpointInitializer implements ApplicationContextInitializer<Gener
|
||||
return handler;
|
||||
}
|
||||
|
||||
private static class RouterFunctionRegister {
|
||||
|
||||
private static void register(GenericApplicationContext context) {
|
||||
context.registerBean(RouterFunction.class,
|
||||
() -> context.getBean(FunctionEndpointFactory.class).functionEndpoints());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ServerListener implements SmartApplicationListener {
|
||||
|
||||
private static Log logger = LogFactory.getLog(ServerListener.class);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.function.web.source;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebEnvironment;
|
||||
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
@@ -27,6 +29,7 @@ import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.context.ConfigurableWebEnvironment;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient.Builder;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -49,7 +52,12 @@ class FunctionExporterInitializer implements ApplicationContextInitializer<Gener
|
||||
if (ClassUtils.isPresent("org.springframework.web.reactive.function.client.WebClient",
|
||||
getClass().getClassLoader())) {
|
||||
if (context.getBeanFactory().getBeanNamesForType(WebClient.Builder.class, false, false).length == 0) {
|
||||
context.registerBean(WebClient.Builder.class, () -> WebClient.builder());
|
||||
context.registerBean(WebClient.Builder.class, new Supplier<WebClient.Builder>() {
|
||||
@Override
|
||||
public Builder get() {
|
||||
return WebClient.builder();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user