Add resttemplate-to-restclient module: RestTemplate deprecation on Spring Framework 7.1 / Boot 4.2.0 vs 4.1.3, method mapping, exchange() trap, bridge URI encoding, RestTestClient, OpenRewrite recipe run, with real transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7M7FEdeEm3APj16Bu
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# resttemplate-to-restclient
|
||||
|
||||
Companion module for the ankurm.com article *RestTemplate Is Deprecated in Spring Framework 7.1: Migrate to RestClient (and TestRestTemplate to RestTestClient)*.
|
||||
Everything runs against **Spring Boot 4.2.0** (Spring Framework 7.1.0) and, for the before/after comparison, against **4.1.3** (Spring Framework 7.0.11). JDK 25 (Temurin 25.0.5), Maven 3.9.
|
||||
|
||||
| Path | What it is |
|
||||
|---|---|
|
||||
| `src/main/.../StudentController` | the real server every client calls: CRUD, a 404, a 500, `/whoami` (echoes the headers the server received), `/search` (echoes the raw query string), `/slow` |
|
||||
| `src/main/.../LegacyStudentClient`, `StudentClient` | the same two operations on `RestTemplate` and on `RestClient` |
|
||||
| `src/main/.../RestClientConfig` | timeouts and an interceptor on `RestClient`, using `HttpClientSettings` |
|
||||
| `src/test/.../MethodMappingTest` | every row of the method-mapping table: the `RestTemplate` call and the `RestClient` call side by side, same server |
|
||||
| `src/test/.../ErrorHandlingTest` | exception types and messages for 404, 500 and a refused connection; a custom `ResponseErrorHandler` moved to `defaultStatusHandler` / `onStatus` |
|
||||
| `src/test/.../ExchangeTrapTest` | `exchange()` on `RestClient` does not apply the default status handlers |
|
||||
| `src/test/.../BridgeTest` | `RestClient.create(restTemplate)`: what it copies (interceptors, error handler, request factory) and the URI-encoding change it does not carry over |
|
||||
| `src/test/.../RequestFactoryTest` | the default HTTP stack of each client as the server sees it (`User-Agent`), and `PATCH` |
|
||||
| `src/test/.../InterceptorBufferingTest` | an interceptor that reads the response body, with and without buffering |
|
||||
| `src/test/.../TimeoutsTest` | `spring.http.clients.*` on `RestClient.Builder` and `RestTemplateBuilder`, and the programmatic `HttpClientSettings` form |
|
||||
| `src/test/.../TestClientMigrationTest` | `TestRestTemplate` and `RestTestClient` asserting the same things |
|
||||
| `src/test/.../MockServerTest` | `MockRestServiceServer.bindTo(...)` on a `RestTemplate` and on a `RestClient.Builder` |
|
||||
| `src/test/.../BuilderBeansTest`, `ConfiguredClientTest` | which client beans Boot registers; the `RestClientConfig` bean |
|
||||
| `src/test/.../RecipeOutputTest` + `recipe/RemoteClient.java` | the class OpenRewrite generated from `src/recipe/before/RemoteClient.java`, run against the real server |
|
||||
| `src/broken/*.java` | not built; `scripts/compile-broken.sh` compiles each with `-Xlint:deprecation` and keeps the compiler's own message |
|
||||
| `scripts/probe-jars.sh`, `scripts/probe-properties.sh` | read the `@Deprecated(since, forRemoval)` annotations and the HTTP-client property metadata straight from the published jars |
|
||||
| `scripts/openrewrite.sh` | runs `io.moderne.java.spring.boot3.MigrateRestTemplateToRestClient` on a scratch copy and stores the diff |
|
||||
| `output/` | every transcript quoted in the article; `./scripts/run-all.sh` regenerates them (files suffixed `-on-4.1.3` are the baseline) |
|
||||
|
||||
Run: `./scripts/run-all.sh`. Timing figures in `output/09-timeouts.txt` are reported in coarse buckets because they drift between runs.
|
||||
|
||||
There is deliberately no `docs/` folder: the explanations live in the article.
|
||||
Reference in New Issue
Block a user