Declarative HTTP Interface Clients (Boot 4)
Define a remote API as an interface with @HttpExchange methods. Boot 4 registers the proxy with
@ImportHttpServices, so do not create a manual factory for every client.
Define and register the interface
java@HttpExchange("/orders") public interface OrderApiClient { @GetExchange("/{id}") OrderDto get(@PathVariable UUID id); @PostExchange OrderDto create(@RequestBody CreateOrderRequest request); } @SpringBootApplication @ImportHttpServices(group = "orders", basePackages = "com.example.client.orders") public class Application { }
Inject OrderApiClient like any other bean. The interface needs no @Component and no
implementation class.
Configure groups and transport
yamlspring: http: clients: connect-timeout: 2s read-timeout: 5s serviceclient: orders: base-url: https://orders.internal.example.com read-timeout: 10s
spring.http.clients.* contains global transport defaults. spring.http.serviceclient.<group>.*
contains per-group settings, and the group name must match @ImportHttpServices.
The default client type is blocking RestClient. Select
HttpServiceGroup.ClientType.WEB_CLIENT for interfaces returning Mono or Flux, and include
the WebClient starter. Group configurers apply to a group, not one interface.
Manual HttpServiceProxyFactory wiring remains valid for one-off clients, but it is the Boot 3
pattern and should not be the default in Boot 4.
Gotchas
- Agent creates a
HttpServiceProxyFactorybean for every client - use@ImportHttpServicesand groups. - Agent adds
@Componentor an implementation to the interface - generated proxies need neither. - Agent uses
spring.http.client.*- global defaults are underspring.http.clients.*; group settings useserviceclient. - Agent hard-codes a host in
@HttpExchangeand sets a group base URL - keep the host in configuration. - Agent returns
MonoorFluxwith the default client - selectWEB_CLIENTexplicitly. - Agent assumes a group configurer customizes one interface - configure the group or separate the group.


