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
Provide AOT support for HttpServiceProxyFactory
clients
#29271
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
theme: aot
An issue related to Ahead-of-time processing
type: enhancement
A general enhancement
Milestone
Comments
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged or decided on
label
Oct 6, 2022
sbrannen
added
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
theme: aot
An issue related to Ahead-of-time processing
labels
Oct 6, 2022
sbrannen
changed the title
support AOT for
Provide AOT support for Oct 6, 2022
HttpServiceProxyFactory
clientsHttpServiceProxyFactory
clients
btw the full code example is https://github.com/joshlong/cloud-native-java-2022/blob/main/e2e5/edge2/src/main/java/com/example/edge2/Edge2Application.java package com.example.edge2;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.core.DecoratingProxy;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.annotation.GetExchange;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
import reactor.core.publisher.Flux;
@SpringBootApplication
@RegisterReflectionForBinding(Customer.class)
@ImportRuntimeHints(Edge2Application.Hints.class)
public class Edge2Application {
static class Hints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints
.proxies()
.registerJdkProxy(
com.example.edge2.CrmClient.class, org.springframework.aop.SpringProxy.class,
org.springframework.aop.framework.Advised.class, DecoratingProxy.class
);
}
}
public static void main(String[] args) {
SpringApplication.run(Edge2Application.class, args);
}
@Bean
ApplicationListener<ApplicationReadyEvent> httpClientRunner(CrmClient crmClient) {
return event -> crmClient.getCustomers().subscribe(System.out::println);
}
@Bean
HttpServiceProxyFactory httpServiceProxyFactory(WebClient.Builder http) {
return WebClientAdapter.createHttpServiceProxyFactory(http.baseUrl("http://localhost:8080/"));
}
@Bean
CrmClient crmClient(HttpServiceProxyFactory httpServiceProxyFactory) {
return httpServiceProxyFactory.createClient(CrmClient.class);
}
}
interface CrmClient {
@GetExchange(url = "/customers")
Flux<Customer> getCustomers();
}
record Customer(Integer id, String name) {
} |
sdeleuze
removed
the
status: waiting-for-triage
An issue we've not yet triaged or decided on
label
Oct 11, 2022
sdeleuze
added a commit
to sdeleuze/spring-framework
that referenced
this issue
Oct 25, 2022
sdeleuze
added a commit
to sdeleuze/spring-framework
that referenced
this issue
Oct 25, 2022
sdeleuze
added a commit
to sdeleuze/spring-framework
that referenced
this issue
Oct 25, 2022
sdeleuze
added a commit
to sdeleuze/spring-framework
that referenced
this issue
Oct 25, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
theme: aot
An issue related to Ahead-of-time processing
type: enhancement
A general enhancement
If i create a declarative HTTP client with
HttpServiceProxyFactory
it fails when I try to turn the application with spring boot 3 snapshots into a graalvm native image. I've been able to make declarative HTTP clients with some tweaks to my app:@RegisterReflectionForBinding
for the DTO my HTTP client interface deals with (e.g.Customer
)RuntimeHintsRegistrar
for the JDK proxy that results:hints.proxies().registerJdkProxy(CrmClient.class, SpringProxy.class, Advised.class, DecoratingProxy.class )
it would be nice to have the framework automatically contribute the hints for me, discovering all the input parameters and return values of my interfaces and supporting them, and registering the types for the proxy that's ultimately created.
The text was updated successfully, but these errors were encountered: