http-service-clients
Companion module for Spring Boot 4 HTTP Service Clients: @HttpExchange Interfaces with RestClient (Complete Guide)
on ankurm.com. Declarative @HttpExchange interfaces registered with @ImportHttpServices, configured
through spring.http.serviceclient.<group>.*, with error handling, retries, authentication and tests.
Everything runs offline: the tests start a small stub upstream (stub/StubServer, JDK HttpServer) on a
random port and the clients call it over real HTTP. Nothing talks to jsonplaceholder.typicode.com.
Versions
| Spring Boot | 4.1.2 |
| Spring Framework | 7.0.10 |
| Spring Security | 7.1.2 (managed by Boot) |
| Resilience4j (retry comparison only) | 2.4.0 |
| JDK | 25 (LTS) |
Run
export JAVA_HOME=/path/to/jdk-25
./scripts/run-all.sh # mvn test; rewrites output/*.txt (11 tests)
./scripts/run-stub.sh # optional: the stub on port 18601, to poke with curl
Files
| Path | What |
|---|---|
src/main/java/.../client/ |
the @HttpExchange interfaces (posts, params, flaky, resilient, bearer, api key, OAuth2, GitHub) |
src/main/java/.../config/HttpClientsConfig.java |
@ImportHttpServices groups and RestClientHttpServiceGroupConfigurer beans |
src/main/java/.../error/ |
status handler, custom exceptions, @RestControllerAdvice |
src/main/java/.../stub/StubServer.java |
the local upstream |
src/main/resources/application.yml |
base URLs, timeouts, default headers, OAuth2 registration |
src/test/java/.../Step01..Step09*Test.java |
one test per article section; each writes its transcript |
output/01..09c-*.txt |
captured output quoted in the article |