Add boot42-upgrade module: Spring Boot 4.2.0 GA vs 4.1.3 upgrade checklist

Re-runs the RC1 checklist on GA and adds SSL-bundle options on the LDAP client,
the migrator fail switch, OpenTelemetry convention spellings, migrated
RestClient/RestTestClient, compiler removal warnings for RestTemplate,
TestRestTemplate and Pulsar, and jar/BOM probes. Transcripts in output/.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b5G8Z7wYEQnr5w4DfG
This commit is contained in:
Claude
2026-11-20 19:27:32 +00:00
parent da700a564f
commit 5f85ec8d53
64 changed files with 1537 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
# boot42-upgrade
Companion module for the ankurm.com article *Spring Boot 4.2 GA: What's New, What's Deprecated and the 4.1 to 4.2 Upgrade Checklist*.
Everything runs against **Spring Boot 4.2.0** (GA, released 19 November 2026; Spring Framework 7.1.0) and, for the before/after comparison, against **4.1.3** (the latest 4.1 patch). JDK 25 (Temurin 25.0.5).
| Path | What it is |
|---|---|
| `pom.xml` / `pom-41.xml` | the same project on 4.2.0 and on 4.1.3 (a `${revision}` parent does not resolve from a repository, hence two files) |
| `src/test/.../DefaultValuePlaceholderTest` | `@DefaultValue` with a `${...}` placeholder: resolved on 4.2, literal text on 4.1.3 (and a startup failure for an `int`) |
| `src/test/.../KafkaAdminBindingTest` | the new `spring.kafka.template.admin.*` / `listener.admin.*` keys: 5 of 5 bind on 4.2, 0 of 5 on 4.1.3 with no error |
| `src/test/.../LdapEmbeddedSslTest` | embedded LDAP `ssl.enabled=true` without a bundle: fails on 4.2, starts on 4.1.3 |
| `src/test/.../SslBundleOptionsTest` | an SSL bundle with `options.ciphers` / `options.enabled-protocols` on the LDAP client fails startup on 4.2 |
| `src/test/.../MigratorTest` | what `spring-boot-properties-migrator` prints for the relocated Tomcat keys, the removed path-matching key, the removed `ignored-meters` key and the deprecated forwarded-headers key; `scripts/migrator-without-actuator.sh` repeats it without Actuator on the classpath |
| `src/test/.../MigratorFailSwitchTest` | `spring.properties.migrator.fail=on-error` / `on-warning` stop the application; `never` does not |
| `src/test/.../ForwardedHeadersTest`, `ForwardedHeadersNewPropertiesTest` | what the container believes for each forwarded-header setting; the milestone-era `spring.mvc.forwarded-headers.header-format` no longer exists in 4.2.0, the settings live under `server.request.header.forwarded.*` |
| `src/test/.../ConventionSpellingsTest` | `management.observations.conventions=open-telemetry` starts on 4.2.0 and switches the server meter to `http.server.request.duration` |
| `src/test/.../MigratedClientsTest` | `RestClient.Builder` (via `PingClient`) and `RestTestClient`, the replacements for `RestTemplateBuilder` and `TestRestTemplate`, on both versions |
| `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` | reads configuration-metadata defaults, the default buildpack builder constants and the BOM versions straight from the published 4.1.3 and 4.2.0 artifacts |
| `output/` | every transcript quoted in the article; `./scripts/run-all.sh` regenerates them |
Run: `./scripts/run-all.sh`. Not executed here (they need Docker, a registry or a running broker): building an image with the new default builder, the registry-backed build cache, AMQP 1.0 against a broker, and the Redis master/replica database change.
There is deliberately no `docs/` folder: the explanations live in the article.
@@ -0,0 +1,6 @@
# 01-default-value-placeholders (Spring Boot 4.1.3, JDK 25)
no demo.* properties set: zone = ${demo.region:eu}-primary plain = static-value
demo.region=ap: zone = ${demo.region:eu}-primary
int property, placeholder default: context FAILED to start
root cause: java.lang.NumberFormatException
For input string: "${demoport.number:8080}"
@@ -0,0 +1,4 @@
# 01-default-value-placeholders (Spring Boot 4.2.0, JDK 25)
no demo.* properties set: zone = eu-primary plain = static-value
demo.region=ap: zone = ap-primary
int property, placeholder default: number = 8080
@@ -0,0 +1,10 @@
# 02-kafka-admin-binding (Spring Boot 4.1.3, JDK 25)
properties supplied: 5
IGNORED spring.kafka.listener.admin.client-id
IGNORED spring.kafka.listener.admin.fail-fast
IGNORED spring.kafka.listener.await-async-results-on-stop
IGNORED spring.kafka.template.admin.client-id
IGNORED spring.kafka.template.admin.fail-fast
bound = 0 of 5
listener.isAwaitAsyncResultsOnStop() = no such method
template.getAdmin() = no such method
@@ -0,0 +1,14 @@
# 02-kafka-admin-binding (Spring Boot 4.2.0, JDK 25)
properties supplied: 5
bound spring.kafka.listener.admin.client-id
bound spring.kafka.listener.admin.fail-fast
bound spring.kafka.listener.await-async-results-on-stop
bound spring.kafka.template.admin.client-id
bound spring.kafka.template.admin.fail-fast
bound = 5 of 5
listener.isAwaitAsyncResultsOnStop() = true
template.getAdmin() = org.springframework.boot.kafka.autoconfigure.KafkaProperties$SimpleAdmin
template admin client-id = template-admin
template admin fail-fast = true
listener admin client-id = listener-admin
listener admin fail-fast = true
@@ -0,0 +1,3 @@
# 03-ldap-embedded-ssl-without-bundle (Spring Boot 4.1.3, JDK 25)
spring.ldap.embedded.ssl.enabled=true, no bundle: context STARTED
embedded server beans: 1
@@ -0,0 +1,4 @@
# 03-ldap-embedded-ssl-without-bundle (Spring Boot 4.2.0, JDK 25)
spring.ldap.embedded.ssl.enabled=true, no bundle: context FAILED to start
java.lang.IllegalStateException
SSL is enabled but no SSL bundle has been set. An SSL bundle providing the server's certificate and private key is required for LDAPS
@@ -0,0 +1 @@
# 04-properties-migrator-report (Spring Boot 4.1.3, JDK 25)
@@ -0,0 +1,17 @@
# 04-properties-migrator-report (Spring Boot 4.2.0, JDK 25)
The use of configuration keys that have been renamed was found in the environment:
Property source 'defaultProperties':
Key: server.tomcat.additional-tld-skip-patterns
Replacement: server.tomcat.servlet.additional-tld-skip-patterns
Key: server.tomcat.redirect-context-root
Replacement: server.tomcat.servlet.redirect-context-root
Key: server.tomcat.use-relative-redirects
Replacement: server.tomcat.servlet.use-relative-redirects
The use of configuration keys that are no longer supported was found in the environment:
Property source 'defaultProperties':
Key: management.metrics.observations.ignored-meters
Reason: Replacement key 'management.metrics.observations.include-active-long-task-timer' uses an incompatible target type
Key: server.forward-headers-strategy
Reason: Replacement key 'server.request.header.forwarded.strategy' uses an incompatible target type
Key: spring.mvc.pathmatch.matching-strategy
Reason: Path matching is no longer configurable
@@ -0,0 +1,3 @@
# 05-resttemplate-compiler-warnings (Spring Boot 4.1.3, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/broken/UsesRestTemplate.java
exit: 0
@@ -0,0 +1,10 @@
# 05-resttemplate-compiler-warnings (Spring Boot 4.2.0, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/broken/UsesRestTemplate.java
src/broken/UsesRestTemplate.java:11: warning: [removal] RestTemplateBuilder in org.springframework.boot.restclient has been deprecated and marked for removal
public String fetch(RestTemplateBuilder builder) {
^
src/broken/UsesRestTemplate.java:12: warning: [removal] RestTemplate in org.springframework.web.client has been deprecated and marked for removal
RestTemplate rest = builder.build();
^
2 warnings
exit: 0
@@ -0,0 +1,3 @@
# 06-testresttemplate-compiler-warnings (Spring Boot 4.1.3, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/broken/UsesTestRestTemplate.java
exit: 0
@@ -0,0 +1,7 @@
# 06-testresttemplate-compiler-warnings (Spring Boot 4.2.0, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/broken/UsesTestRestTemplate.java
src/broken/UsesTestRestTemplate.java:6: warning: [removal] TestRestTemplate in org.springframework.boot.resttestclient has been deprecated and marked for removal
public String ping(TestRestTemplate rest) {
^
1 warning
exit: 0
@@ -0,0 +1,3 @@
# 07-pulsar-compiler-warnings (Spring Boot 4.1.3, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/broken/UsesPulsarProperties.java
exit: 0
@@ -0,0 +1,10 @@
# 07-pulsar-compiler-warnings (Spring Boot 4.2.0, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/broken/UsesPulsarProperties.java
src/broken/UsesPulsarProperties.java:7: warning: [removal] PulsarProperties in org.springframework.boot.pulsar.autoconfigure has been deprecated and marked for removal
PulsarProperties properties = new PulsarProperties();
^
src/broken/UsesPulsarProperties.java:7: warning: [removal] PulsarProperties in org.springframework.boot.pulsar.autoconfigure has been deprecated and marked for removal
PulsarProperties properties = new PulsarProperties();
^
2 warnings
exit: 0
@@ -0,0 +1,2 @@
# 08-ssl-bundle-options-ldap (Spring Boot 4.1.3, JDK 25)
spring.ldap.ssl.bundle does not exist in 4.1.3: nothing to compare
@@ -0,0 +1,6 @@
# 08-ssl-bundle-options-ldap (Spring Boot 4.2.0, JDK 25)
bundle without options: context STARTED, LdapContextSource beans: 1
bundle with options.ciphers: context FAILED to start
SSL options cannot be specified with LDAP
bundle with options.enabled-protocols: context FAILED to start
SSL options cannot be specified with LDAP
@@ -0,0 +1,5 @@
# 09-conventions-spellings (Spring Boot 4.1.3, JDK 25)
open-telemetry -> starts, server meter: [http.server.requests]
opentelemetry -> starts, server meter: [http.server.requests]
OPEN_TELEMETRY -> starts, server meter: [http.server.requests]
micrometer -> starts, server meter: [http.server.requests]
@@ -0,0 +1,5 @@
# 09-conventions-spellings (Spring Boot 4.2.0, JDK 25)
open-telemetry -> starts, server meter: [http.server.request.duration]
opentelemetry -> starts, server meter: [http.server.request.duration]
OPEN_TELEMETRY -> starts, server meter: [http.server.request.duration]
micrometer -> starts, server meter: [http.server.requests]
@@ -0,0 +1,22 @@
# 10-config-defaults (spring-configuration-metadata.json from the 4.1.3 and 4.2.0 jars)
key 4.1.3 4.2.0
server.tomcat.use-relative-redirects -> server.tomcat.servlet.use-relative-redirects
4.1.3: False 4.2.0: True
server.tomcat.redirect-context-root -> server.tomcat.servlet.redirect-context-root
4.1.3: True 4.2.0: True
spring.rabbitmq.username
4.1.3: 'guest' 4.2.0: 'guest'
spring.rabbitmq.password
4.1.3: 'guest' 4.2.0: 'guest'
spring.rabbitmq.username -> spring.amqp.rabbitmq.username
4.1.3: 'guest' 4.2.0: (none)
spring.rabbitmq.password -> spring.amqp.rabbitmq.password
4.1.3: 'guest' 4.2.0: (none)
spring.rabbitmq.template.exchange -> spring.amqp.rabbitmq.template.exchange
4.1.3: '' 4.2.0: (none)
spring.rabbitmq.template.routing-key -> spring.amqp.rabbitmq.template.routing-key
4.1.3: '' 4.2.0: (none)
management.observations.conventions
4.1.3: (absent) 4.2.0: 'micrometer'
management.opentelemetry.otlp.endpoint
4.1.3: (absent) 4.2.0: (none)
@@ -0,0 +1,8 @@
# 11-buildpack-defaults (javap -constants on BuildRequest in spring-boot-buildpack-platform)
[4.1.3]
DEFAULT_BUILDER_IMAGE_NAME = "paketobuildpacks/builder-noble-java-tiny";
DEFAULT_BUILDER_IMAGE_REF = "paketobuildpacks/builder-noble-java-tiny:latest";
[4.2.0]
DEFAULT_BUILDER_IMAGE_NAME = "paketobuildpacks/ubuntu-resolute-builder";
DEFAULT_BUILDER_IMAGE_REF = "paketobuildpacks/ubuntu-resolute-builder:latest";
DEFAULT_RUN_IMAGE_NAME = "paketobuildpacks/ubuntu-resolute-run-tiny";
+38
View File
@@ -0,0 +1,38 @@
# 12-bom-versions (spring-boot-dependencies POM properties)
property 4.1.3 4.2.0
spring-framework.version 7.0.11 7.1.0
spring-security.version 7.1.3 7.2.0
spring-data-bom.version 2026.0.3 2026.1.0
spring-batch.version 6.0.6 6.1.0
spring-kafka.version 4.1.3 4.2.0
spring-amqp.version 4.1.3 4.2.0
spring-integration.version 7.1.3 7.2.0
spring-graphql.version 2.0.7 2.1.0
spring-session.version 4.1.2 4.2.0
spring-ldap.version 4.1.3 4.2.0
hibernate.version 7.4.15.Final 7.4.15.Final
jackson-bom.version 3.1.8 3.1.8
jackson-2-bom.version 2.21.8 2.21.8
micrometer.version 1.17.3 1.18.0
micrometer-tracing.version 1.7.3 1.8.0
opentelemetry.version 1.62.0 1.68.0
netty.version 4.2.20.Final 4.2.20.Final
tomcat.version 11.0.27 11.0.27
jetty.version 12.1.15 12.1.15
flyway.version 12.4.0 12.11.0
junit-jupiter.version 6.0.3 6.1.3
mockito.version 5.23.0 5.24.0
assertj.version 3.27.7 3.27.7
lettuce.version 7.5.2.RELEASE 7.8.0.RELEASE
thymeleaf.version 3.1.7.RELEASE 3.1.7.RELEASE
logback.version 1.5.38 1.6.6
log4j2.version 2.25.5 2.26.1
snakeyaml.version 2.6 2.7
kotlin.version 2.3.21 2.4.21
h2.version 2.4.240 2.5.252
testcontainers.version 2.0.5 2.0.5
reactor-bom.version 2025.0.9 2026.0.0
janino.version 3.1.12 (not managed)
properties: 195 in 4.1.3, 195 in 4.2.0; changed 62, added 3, removed 3
removed: janino.version, rabbit-amqp-client.version, rabbit-stream-client.version
added: rabbitmq-amqp-client.version, rabbitmq-client.version, rabbitmq-stream-client.version
@@ -0,0 +1,3 @@
# 13-migrated-clients (Spring Boot 4.1.3, JDK 25)
RestClient.Builder GET /hello/rest-client -> hello rest-client
RestTestClient GET /hello/rest-test-client -> hello rest-test-client
@@ -0,0 +1,3 @@
# 13-migrated-clients (Spring Boot 4.2.0, JDK 25)
RestClient.Builder GET /hello/rest-client -> hello rest-client
RestTestClient GET /hello/rest-test-client -> hello rest-test-client
@@ -0,0 +1,3 @@
# 14-migrated-client-compiler (Spring Boot 4.1.3, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/main/java/com/ankurm/boot42up/PingClient.java
exit: 0
@@ -0,0 +1,3 @@
# 14-migrated-client-compiler (Spring Boot 4.2.0, JDK 25.0.5.1)
$ javac -Xlint:deprecation -cp <module classpath> -d target/broken src/main/java/com/ankurm/boot42up/PingClient.java
exit: 0
@@ -0,0 +1,9 @@
# 15-amqp-starters (published POMs: description and boot-level dependency)
[4.1.3]
spring-boot-starter-amqp "Starter for using Spring AMQP and Rabbit MQ" -> spring-boot-amqp
spring-boot-starter-rabbitmq (not published in 4.1.3)
spring-boot-starter-amqp-rabbitmq (not published in 4.1.3)
[4.2.0]
spring-boot-starter-amqp "Starter for generic AMQP 1.0 support" -> spring-boot-amqp
spring-boot-starter-rabbitmq "Starter for using RabbitMQ messaging and streaming broker" -> spring-boot-rabbitmq
spring-boot-starter-amqp-rabbitmq "Starter for using Spring AMQP with Rabbit MQ over AMQP 1.0 protocol" -> spring-boot-amqp-rabbitmq
@@ -0,0 +1,5 @@
# 16-migrator-fail-switch (spring-boot-properties-migrator 4.2.0)
spring.properties.migrator.fail default=never
value: NEVER
value: ON_ERROR
value: ON_WARNING
@@ -0,0 +1,4 @@
# 17-migrator-fail-switch (Spring Boot 4.1.3, JDK 25)
spring.properties.migrator.fail=never -> application STARTED
spring.properties.migrator.fail=on-error -> application STARTED
spring.properties.migrator.fail=on-warning -> application STARTED
@@ -0,0 +1,4 @@
# 17-migrator-fail-switch (Spring Boot 4.2.0, JDK 25)
spring.properties.migrator.fail=never -> application STARTED
spring.properties.migrator.fail=on-error -> application FAILED to start: IllegalStateException
spring.properties.migrator.fail=on-warning -> application FAILED to start: IllegalStateException
@@ -0,0 +1,10 @@
# 18-forwarded-headers (Spring Boot 4.1.3, JDK 25)
none/x-forwarded scheme=http secure=false host=localhost port=<random>
none/rfc7239 scheme=http secure=false host=localhost port=<random>
native/x-forwarded scheme=https secure=true host=shop.example.com port=443
native/rfc7239 scheme=http secure=false host=localhost port=<random>
framework/x-forwarded scheme=https secure=true host=shop.example.com port=443
framework/rfc7239 scheme=https secure=true host=shop.example.com port=443
framework+standard/x-forwarded scheme=https secure=true host=shop.example.com port=443
framework+standard/rfc7239 scheme=https secure=true host=shop.example.com port=443
header-format=forwarded -> started (property ignored)
@@ -0,0 +1,10 @@
# 18-forwarded-headers (Spring Boot 4.2.0, JDK 25)
none/x-forwarded scheme=http secure=false host=localhost port=<random>
none/rfc7239 scheme=http secure=false host=localhost port=<random>
native/x-forwarded scheme=https secure=true host=shop.example.com port=443
native/rfc7239 scheme=http secure=false host=localhost port=<random>
framework/x-forwarded scheme=https secure=true host=shop.example.com port=443
framework/rfc7239 scheme=http secure=false host=localhost port=<random>
framework+standard/x-forwarded scheme=https secure=true host=shop.example.com port=443
framework+standard/rfc7239 scheme=http secure=false host=localhost port=<random>
header-format=forwarded -> started (property ignored)
@@ -0,0 +1,2 @@
# 19-forwarded-headers-new-properties (Spring Boot 4.1.3, JDK 25)
server.request.header.forwarded.* does not exist in 4.1.3: nothing to compare
@@ -0,0 +1,22 @@
# 19-forwarded-headers-new-properties (Spring Boot 4.2.0, JDK 25)
strategy=framework
x-forwarded scheme=https secure=true host=shop.example.com
rfc7239 scheme=http secure=false host=localhost
strategy=framework naming=x-forwarded
x-forwarded scheme=https secure=true host=shop.example.com
rfc7239 scheme=http secure=false host=localhost
strategy=framework naming=rfc-7239
x-forwarded scheme=http secure=false host=localhost
rfc7239 scheme=https secure=true host=shop.example.com
strategy=web-server naming=rfc-7239
x-forwarded FAILED: Tomcat does not support RFC 7239 or 'prefix' forwarded header
rfc7239 FAILED: Tomcat does not support RFC 7239 or 'prefix' forwarded header
strategy=none
x-forwarded scheme=http secure=false host=localhost
rfc7239 scheme=http secure=false host=localhost
server.forward-headers-strategy=framework
x-forwarded scheme=https secure=true host=shop.example.com
rfc7239 scheme=http secure=false host=localhost
server.forward-headers-strategy=framework mvc.header-format=standard
x-forwarded scheme=https secure=true host=shop.example.com
rfc7239 scheme=http secure=false host=localhost
@@ -0,0 +1,15 @@
# 20-migrator-without-actuator (Spring Boot 4.2.0, JDK 25)
The use of configuration keys that have been renamed was found in the environment:
Property source 'defaultProperties':
Key: server.tomcat.additional-tld-skip-patterns
Replacement: server.tomcat.servlet.additional-tld-skip-patterns
Key: server.tomcat.redirect-context-root
Replacement: server.tomcat.servlet.redirect-context-root
Key: server.tomcat.use-relative-redirects
Replacement: server.tomcat.servlet.use-relative-redirects
The use of configuration keys that are no longer supported was found in the environment:
Property source 'defaultProperties':
Key: server.forward-headers-strategy
Reason: Replacement key 'server.request.header.forwarded.strategy' uses an incompatible target type
Key: spring.mvc.pathmatch.matching-strategy
Reason: Path matching is no longer configurable
+87
View File
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.1.3</version>
<relativePath/>
</parent>
<groupId>com.ankurm</groupId>
<artifactId>boot42-upgrade</artifactId>
<version>1.0.0</version>
<name>boot42-upgrade</name>
<description>Spring Boot 4.2.0 upgrade checklist: each claim run against 4.2.0 and 4.1.3</description>
<properties>
<java.version>25</java.version>
<boot.label>4.1.3</boot.label>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-restclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ldap</artifactId>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-opentelemetry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-resttestclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<boot.label>${boot.label}</boot.label>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
+87
View File
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.2.0</version>
<relativePath/>
</parent>
<groupId>com.ankurm</groupId>
<artifactId>boot42-upgrade</artifactId>
<version>1.0.0</version>
<name>boot42-upgrade</name>
<description>Spring Boot 4.2.0 GA upgrade checklist: each claim run against 4.2.0 and 4.1.3</description>
<properties>
<java.version>25</java.version>
<boot.label>4.2.0</boot.label>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-restclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ldap</artifactId>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-opentelemetry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-resttestclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<boot.label>${boot.label}</boot.label>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Compiles each file in src/broken/ with -Xlint:deprecation against the module classpath of the
# given pom (default pom.xml = 4.2.0; pass pom-41.xml for the 4.1.3 baseline) and stores the
# compiler's own messages in output/05-... and output/06-... (suffix -on-4.1.3 for the baseline).
set -u
cd "$(dirname "$0")/.."
POM="${1:-pom.xml}"
LABEL=$(grep -m1 '<boot.label>' "$POM" | sed -E 's/.*<boot.label>(.*)<\/boot.label>.*/\1/')
SUFFIX=""; [[ "$LABEL" == 4.2* ]] || SUFFIX="-on-$LABEL"
mvn -B -q -f "$POM" dependency:build-classpath -Dmdep.outputFile=target/cp.txt >/dev/null 2>&1
# spring-boot-pulsar is not a dependency of the module (it would auto-configure a Pulsar client);
# it is added to the compile classpath for UsesPulsarProperties only.
PULSAR="$HOME/.m2/repository/org/springframework/boot/spring-boot-pulsar/$LABEL/spring-boot-pulsar-$LABEL.jar"
[ -f "$PULSAR" ] || mvn -B -q dependency:get -Dartifact="org.springframework.boot:spring-boot-pulsar:$LABEL" >/dev/null 2>&1
CP="$(cat target/cp.txt):$PULSAR"
compile_one() { # <source> <outfile-base> <title>
local src="$1" base="$2" title="$3" out="output/$2$SUFFIX.txt"
rm -rf target/broken && mkdir -p target/broken
{
echo "# $base (Spring Boot $LABEL, JDK $(javac -version 2>&1 | grep -v Picked | awk '{print $2}'))"
echo "\$ javac -Xlint:deprecation -cp <module classpath> -d target/broken $src"
javac -Xlint:deprecation -cp "$CP" -d target/broken "$src" 2>&1 | grep -v '^Picked up' | sed -e "s#^$(pwd)/##"
echo "exit: ${PIPESTATUS[0]}"
} > "$out"
cat "$out"
}
compile_one src/broken/UsesRestTemplate.java 05-resttemplate-compiler-warnings "RestTemplate"
{ compile_one src/broken/UsesTestRestTemplate.java 06-testresttemplate-compiler-warnings "TestRestTemplate"; } >/dev/null
{ compile_one src/broken/UsesPulsarProperties.java 07-pulsar-compiler-warnings "Pulsar"; } >/dev/null
# The migrated form must compile with no [removal] warning at all.
{ compile_one src/main/java/com/ankurm/boot42up/PingClient.java 14-migrated-client-compiler "PingClient"; } >/dev/null
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Re-runs MigratorTest on 4.2.0 with the two Actuator-related starters removed from the classpath and
# stores what the migrator prints in output/20-migrator-without-actuator.txt. The migrator can only
# report a key whose metadata is on the classpath, and the metadata for management.* keys ships in
# the Actuator/Micrometer jars.
set -euo pipefail
cd "$(dirname "$0")/.."
python3 - <<'PY'
import re
s = open("pom.xml").read()
for art in ("spring-boot-starter-actuator", "spring-boot-starter-opentelemetry"):
s = re.sub(r"\s*<dependency>\s*<groupId>org.springframework.boot</groupId>\s*<artifactId>%s</artifactId>\s*</dependency>" % art, "", s)
open("pom-no-actuator.xml", "w").write(s)
PY
cp output/04-properties-migrator-report.txt target/04-with-actuator.txt
# ConventionSpellingsTest and MigratedClientsTest need Actuator/Micrometer; only MigratorTest runs here
mvn -B -q -f pom-no-actuator.xml test -Dtest=MigratorTest -Dsurefire.failIfNoSpecifiedTests=false >/dev/null
sed 's/^# 04-properties-migrator-report/# 20-migrator-without-actuator/' output/04-properties-migrator-report.txt > output/20-migrator-without-actuator.txt
cp target/04-with-actuator.txt output/04-properties-migrator-report.txt
rm -f pom-no-actuator.xml
cat output/20-migrator-without-actuator.txt
+143
View File
@@ -0,0 +1,143 @@
#!/usr/bin/env bash
# Reads facts straight out of the published Spring Boot 4.1.3 and 4.2.0 artifacts on Maven Central:
# output/10-config-defaults.txt defaults from META-INF/spring-configuration-metadata.json
# output/11-buildpack-defaults.txt default builder / run image constants (javap -constants)
# output/12-bom-versions.txt spring-boot-dependencies BOM properties, 4.1.3 vs 4.2.0
# Needs JDK 25 (javap), python3, curl, unzip.
set -euo pipefail
cd "$(dirname "$0")/.."
OLD=4.1.3; NEW=4.2.0
W=target/probe; mkdir -p "$W" output
M=https://repo1.maven.org/maven2/org/springframework/boot
fetch() { # <artifact> <version> <ext>
local f="$W/$1-$2.$3"
[ -s "$f" ] || curl -sfL -o "$f" "$M/$1/$2/$1-$2.$3"
echo "$f"
}
unpack() { # <artifact> <version> -> dir
local d="$W/x-$2/$1"
[ -d "$d" ] || { mkdir -p "$d"; unzip -q -o "$(fetch "$1" "$2" jar)" -d "$d"; }
echo "$d"
}
for v in "$OLD" "$NEW"; do for a in spring-boot-tomcat spring-boot-micrometer-observation spring-boot-opentelemetry spring-boot-buildpack-platform; do unpack $a $v >/dev/null; done; done
for a in spring-boot-amqp; do unpack $a $OLD >/dev/null; done
for a in spring-boot-rabbitmq spring-boot-amqp-rabbitmq; do unpack $a $NEW >/dev/null; done
# ---- 10: configuration metadata defaults -------------------------------------------------------
python3 - "$W" "$OLD" "$NEW" > output/10-config-defaults.txt <<'PY'
import json, sys, subprocess, os
W, OLD, NEW = sys.argv[1:4]
# (artifact in 4.1.3, artifact in 4.2.0, key in 4.1.3, key in 4.2.0)
ROWS = [
("spring-boot-tomcat", "spring-boot-tomcat", "server.tomcat.use-relative-redirects", "server.tomcat.servlet.use-relative-redirects"),
("spring-boot-tomcat", "spring-boot-tomcat", "server.tomcat.redirect-context-root", "server.tomcat.servlet.redirect-context-root"),
("spring-boot-amqp", "spring-boot-rabbitmq", "spring.rabbitmq.username", "spring.rabbitmq.username"),
("spring-boot-amqp", "spring-boot-rabbitmq", "spring.rabbitmq.password", "spring.rabbitmq.password"),
("spring-boot-amqp", "spring-boot-amqp-rabbitmq", "spring.rabbitmq.username", "spring.amqp.rabbitmq.username"),
("spring-boot-amqp", "spring-boot-amqp-rabbitmq", "spring.rabbitmq.password", "spring.amqp.rabbitmq.password"),
("spring-boot-amqp", "spring-boot-amqp-rabbitmq", "spring.rabbitmq.template.exchange", "spring.amqp.rabbitmq.template.exchange"),
("spring-boot-amqp", "spring-boot-amqp-rabbitmq", "spring.rabbitmq.template.routing-key", "spring.amqp.rabbitmq.template.routing-key"),
("spring-boot-micrometer-observation", "spring-boot-micrometer-observation", "management.observations.conventions", "management.observations.conventions"),
("spring-boot-opentelemetry", "spring-boot-opentelemetry", "management.opentelemetry.otlp.endpoint", "management.opentelemetry.otlp.endpoint"),
]
def load(art, ver):
d = os.path.join(W, f"x-{ver}", art, "META-INF", "spring-configuration-metadata.json")
if not os.path.exists(d):
return {}
return {p["name"]: p for p in json.load(open(d))["properties"]}
print(f"# 10-config-defaults (spring-configuration-metadata.json from the {OLD} and {NEW} jars)")
print(f"{'key':<52} {OLD:<16} {NEW}")
for a_old, a_new, k_old, k_new in ROWS:
o = load(a_old, OLD).get(k_old); n = load(a_new, NEW).get(k_new)
def show(p, key):
if p is None: return "(absent)"
d = p.get("defaultValue", "(none)")
d = repr(d) if d != "(none)" else d
dep = p.get("deprecation")
return d + (" [deprecated]" if dep else "")
label = k_old if k_old == k_new else f"{k_old} -> {k_new}"
print(f"{label}")
print(f"{'':<4}{OLD}: {show(o, k_old):<24} {NEW}: {show(n, k_new)}")
PY
# ---- 11: buildpack defaults --------------------------------------------------------------------
{
echo "# 11-buildpack-defaults (javap -constants on BuildRequest in spring-boot-buildpack-platform)"
for v in "$OLD" "$NEW"; do
d=$(unpack spring-boot-buildpack-platform "$v")
echo "[$v]"
javap -constants -p -cp "$d" org.springframework.boot.buildpack.platform.build.BuildRequest 2>&1 \
| grep -E 'static final java.lang.String DEFAULT_' | sed -E 's/^ +static final java.lang.String //'
done
} > output/11-buildpack-defaults.txt
# ---- 12: BOM versions --------------------------------------------------------------------------
python3 - "$W" "$OLD" "$NEW" > output/12-bom-versions.txt <<'PY'
import re, sys, subprocess, os
W, OLD, NEW = sys.argv[1:4]
def props(v):
f = os.path.join(W, f"spring-boot-dependencies-{v}.pom")
txt = open(f).read()
block = re.search(r"<properties>(.*?)</properties>", txt, re.S).group(1)
return dict(re.findall(r"<([A-Za-z0-9.\-]+)>([^<]+)</\1>", block))
for v in (OLD, NEW):
subprocess.run(["curl", "-sfL", "-o", os.path.join(W, f"spring-boot-dependencies-{v}.pom"),
f"https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/{v}/spring-boot-dependencies-{v}.pom"], check=True)
o, n = props(OLD), props(NEW)
WANT = ["spring-framework.version","spring-security.version","spring-data-bom.version","spring-batch.version",
"spring-kafka.version","spring-amqp.version","spring-integration.version","spring-graphql.version",
"spring-session.version","spring-ldap.version","hibernate.version","jackson-bom.version","jackson-2-bom.version",
"micrometer.version","micrometer-tracing.version","opentelemetry.version","netty.version","tomcat.version",
"jetty.version","flyway.version","junit-jupiter.version","mockito.version","assertj.version","lettuce.version",
"thymeleaf.version","logback.version","log4j2.version","snakeyaml.version","kotlin.version","h2.version",
"testcontainers.version","reactor-bom.version","janino.version"]
print(f"# 12-bom-versions (spring-boot-dependencies POM properties)")
print(f"{'property':<28}{OLD:<18}{NEW}")
for k in WANT:
print(f"{k:<28}{o.get(k,'(not managed)'):<18}{n.get(k,'(not managed)')}")
changed = [k for k in n if k in o and n[k] != o[k]]
added = [k for k in n if k not in o]; removed = [k for k in o if k not in n]
print(f"properties: {len(o)} in {OLD}, {len(n)} in {NEW}; changed {len(changed)}, added {len(added)}, removed {len(removed)}")
print("removed: " + ", ".join(sorted(removed)))
print("added: " + ", ".join(sorted(added)))
PY
# ---- 15: what the AMQP starter names mean ------------------------------------------------------
python3 - "$W" "$OLD" "$NEW" > output/15-amqp-starters.txt <<'PY'
import re, sys, urllib.request
W, OLD, NEW = sys.argv[1:4]
def pom(art, ver):
url = f"https://repo1.maven.org/maven2/org/springframework/boot/{art}/{ver}/{art}-{ver}.pom"
try:
return urllib.request.urlopen(url).read().decode()
except Exception:
return None
print("# 15-amqp-starters (published POMs: description and boot-level dependency)")
for ver in (OLD, NEW):
print(f"[{ver}]")
for art in ("spring-boot-starter-amqp", "spring-boot-starter-rabbitmq", "spring-boot-starter-amqp-rabbitmq"):
t = pom(art, ver)
if t is None:
print(f" {art:<36} (not published in {ver})")
continue
desc = re.search(r"<description>(.*?)</description>", t, re.S).group(1).strip()
deps = [d for d in re.findall(r"<artifactId>(spring-boot-[a-z0-9-]+)</artifactId>", t)[1:] if d != "spring-boot-starter"]
print(f" {art:<36} \"{desc}\" -> {', '.join(deps)}")
PY
# ---- 16: properties-migrator failure switch ----------------------------------------------------
{
echo "# 16-migrator-fail-switch (spring-boot-properties-migrator $NEW)"
d=$(unpack spring-boot-properties-migrator "$NEW")
python3 - "$d" <<'PY'
import json, sys
d = json.load(open(sys.argv[1] + "/META-INF/spring-configuration-metadata.json"))
for p in d["properties"]:
print(f"{p['name']} default={p.get('defaultValue')}")
PY
javap -constants -p -cp "$d" 'org.springframework.boot.context.properties.migrator.PropertiesMigrationListener$Fail' 2>&1 \
| grep -E 'public static final' | sed -E 's/.*Fail //;s/;//' | sed 's/^/ value: /'
} > output/16-migrator-fail-switch.txt
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Regenerates every file in output/ on Spring Boot 4.2.0 (GA) and on the 4.1.3 baseline.
# Needs JDK 25 and Maven 3.9 on PATH, plus network access to Maven Central.
set -euo pipefail
cd "$(dirname "$0")/.."
mvn -B -q test
mvn -B -q -f pom-41.xml test
scripts/compile-broken.sh pom.xml >/dev/null
scripts/compile-broken.sh pom-41.xml >/dev/null
scripts/probe-jars.sh
scripts/migrator-without-actuator.sh >/dev/null
echo "done: $(ls output | wc -l) files in output/"
@@ -0,0 +1,10 @@
import org.springframework.boot.pulsar.autoconfigure.PulsarProperties;
/** Not part of the build. compile-broken.sh compiles it with -Xlint:deprecation. */
public class UsesPulsarProperties {
public Object client() {
PulsarProperties properties = new PulsarProperties();
return properties.getClient();
}
}
@@ -0,0 +1,15 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.boot.restclient.RestTemplateBuilder;
/**
* Not part of the build. scripts/compile-broken.sh compiles it with -Xlint:deprecation and
* commits the compiler's own message. RestTemplate and the Boot builder around it are
* deprecated in Spring Framework 7.1 / Spring Boot 4.2.
*/
public class UsesRestTemplate {
public String fetch(RestTemplateBuilder builder) {
RestTemplate rest = builder.build();
return rest.getForObject("http://localhost:8080/ping", String.class);
}
}
@@ -0,0 +1,9 @@
import org.springframework.boot.resttestclient.TestRestTemplate;
/** Not part of the build. compile-broken.sh compiles it with -Xlint:deprecation. */
public class UsesTestRestTemplate {
public String ping(TestRestTemplate rest) {
return rest.getForObject("/ping", String.class);
}
}
@@ -0,0 +1,12 @@
package com.ankurm.boot42up;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
/**
* A non-String property with a placeholder default. On 4.1.x the literal text
* {@code ${demo.port:8080}} cannot be converted to int, so the context fails to start.
*/
@ConfigurationProperties("demoport")
public record DemoPort(@DefaultValue("${demoport.number:8080}") int number) {
}
@@ -0,0 +1,16 @@
package com.ankurm.boot42up;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
/**
* Constructor-bound properties whose defaults contain placeholders.
*
* <p>Spring Boot 4.2.0-M2 made {@code @DefaultValue} resolve property placeholders during
* binding. On 4.1.x the same annotation value is taken literally.
*/
@ConfigurationProperties("demo")
public record DemoProperties(
@DefaultValue("${demo.region:eu}-primary") String zone,
@DefaultValue("static-value") String plain) {
}
@@ -0,0 +1,14 @@
package com.ankurm.boot42up;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
class HelloController {
@GetMapping("/hello/{name}")
String hello(@PathVariable String name) {
return "hello " + name;
}
}
@@ -0,0 +1,22 @@
package com.ankurm.boot42up;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
/**
* The migrated form of src/broken/UsesRestTemplate.java: RestClient.Builder (injected by Boot)
* instead of RestTemplateBuilder, and body(...) instead of getForObject(...).
*/
@Component
public class PingClient {
private final RestClient rest;
PingClient(RestClient.Builder builder) {
this.rest = builder.build();
}
public String fetch(String url) {
return this.rest.get().uri(url).retrieve().body(String.class);
}
}
@@ -0,0 +1,17 @@
package com.ankurm.boot42up;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Deliberately has no @ConfigurationPropertiesScan: DemoProperties and DemoPort exist to show a
* difference between 4.1 and 4.2 (on 4.1.3 DemoPort cannot even bind), so the tests enable them
* one at a time instead of letting them break every application start.
*/
@SpringBootApplication
public class UpgradeApplication {
public static void main(String[] args) {
SpringApplication.run(UpgradeApplication.class, args);
}
}
@@ -0,0 +1,23 @@
package com.ankurm.boot42up;
import jakarta.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/** Echoes what the servlet container believes about the request, after any forwarded-header handling. */
@RestController
class WhoAmIController {
@GetMapping("/whoami")
Map<String, Object> whoAmI(HttpServletRequest request) {
Map<String, Object> m = new LinkedHashMap<>();
m.put("scheme", request.getScheme());
m.put("secure", request.isSecure());
m.put("serverName", request.getServerName());
m.put("serverPort", request.getServerPort());
m.put("remoteAddr", request.getRemoteAddr());
return m;
}
}
@@ -0,0 +1,32 @@
package com.ankurm.boot42up;
import java.util.Map;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.web.client.RestClient;
/** Starts the real application with the given properties on a random port. */
final class BootRun {
private BootRun() {
}
static ConfigurableApplicationContext start(String... props) {
return new SpringApplicationBuilder(UpgradeApplication.class)
.web(WebApplicationType.SERVLET)
.properties(props)
.properties("server.port=0", "spring.main.banner-mode=off", "logging.level.root=WARN")
.run();
}
static RestClient client(ConfigurableApplicationContext ctx) {
Environment env = ctx.getEnvironment();
return RestClient.create("http://localhost:" + env.getProperty("local.server.port"));
}
static Map<?, ?> whoAmI(ConfigurableApplicationContext ctx, Map<String, String> headers) {
return client(ctx).get().uri("/whoami").headers(h -> headers.forEach(h::add)).retrieve().body(Map.class);
}
}
@@ -0,0 +1,65 @@
package com.ankurm.boot42up;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import io.micrometer.core.instrument.MeterRegistry;
import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.client.RestClient;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The reference documentation says management.observations.conventions=open-telemetry. On
* 4.2.0-RC1 that spelling failed to start. This starts the application once per spelling on the
* version under test and records whether it starts and which server HTTP meter it ends up with.
*/
class ConventionSpellingsTest {
@Test
void spellings() throws Exception {
Transcript t = new Transcript("09-conventions-spellings");
Map<String, String> outcome = new LinkedHashMap<>();
for (String value : List.of("open-telemetry", "opentelemetry", "OPEN_TELEMETRY", "micrometer")) {
String result;
try (ConfigurableApplicationContext ctx = new SpringApplicationBuilder(UpgradeApplication.class)
.web(WebApplicationType.SERVLET)
.properties("server.port=0", "spring.main.banner-mode=off",
"management.observations.conventions=" + value, "management.otlp.metrics.export.enabled=false",
"management.opentelemetry.tracing.export.otlp.enabled=false")
.run()) {
String port = ctx.getEnvironment().getProperty("local.server.port");
RestClient.create().get().uri("http://localhost:" + port + "/hello/x").retrieve().body(String.class);
MeterRegistry registry = ctx.getBean(MeterRegistry.class);
for (int i = 0; i < 100 && registry.getMeters().stream()
.noneMatch(m -> m.getId().getName().startsWith("http.server.request")
&& !m.getId().getName().endsWith(".active")); i++) {
Thread.sleep(50);
}
result = "starts, server meter: " + registry.getMeters().stream()
.map(m -> m.getId().getName())
.filter(n -> n.startsWith("http.server.request") && !n.endsWith(".active"))
.distinct()
.sorted()
.toList();
}
catch (Exception ex) {
result = "FAILS to start";
}
outcome.put(value, result);
t.line(String.format("%-16s -> %s", value, result));
}
t.write();
if (Transcript.is42()) {
assertThat(outcome.get("open-telemetry")).contains("http.server.request.duration");
assertThat(outcome.get("micrometer")).contains("http.server.requests");
}
else {
assertThat(outcome.get("micrometer")).contains("http.server.requests");
}
}
}
@@ -0,0 +1,68 @@
package com.ankurm.boot42up;
import org.junit.jupiter.api.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
class DefaultValuePlaceholderTest {
@EnableConfigurationProperties(DemoProperties.class)
static class StringConfig {
}
@EnableConfigurationProperties(DemoPort.class)
static class PortConfig {
}
@Test
void placeholderInDefaultValue() {
Transcript t = new Transcript("01-default-value-placeholders");
new ApplicationContextRunner().withUserConfiguration(StringConfig.class).run(ctx -> {
DemoProperties p = ctx.getBean(DemoProperties.class);
t.line("no demo.* properties set: zone = " + p.zone() + " plain = " + p.plain());
if (Transcript.is42()) {
assertThat(p.zone()).isEqualTo("eu-primary");
}
else {
assertThat(p.zone()).isEqualTo("${demo.region:eu}-primary");
}
});
new ApplicationContextRunner().withUserConfiguration(StringConfig.class)
.withPropertyValues("demo.region=ap")
.run(ctx -> {
DemoProperties p = ctx.getBean(DemoProperties.class);
t.line("demo.region=ap: zone = " + p.zone());
if (Transcript.is42()) {
assertThat(p.zone()).isEqualTo("ap-primary");
}
else {
assertThat(p.zone()).isEqualTo("${demo.region:eu}-primary");
}
});
new ApplicationContextRunner().withUserConfiguration(PortConfig.class).run(ctx -> {
if (Transcript.is42()) {
assertThat(ctx).hasNotFailed();
t.line("int property, placeholder default: number = " + ctx.getBean(DemoPort.class).number());
assertThat(ctx.getBean(DemoPort.class).number()).isEqualTo(8080);
}
else {
assertThat(ctx).hasFailed();
Throwable root = rootCause(ctx.getStartupFailure());
t.line("int property, placeholder default: context FAILED to start");
t.line("root cause: " + root.getClass().getName());
t.line(" " + root.getMessage());
}
});
t.write();
}
private static Throwable rootCause(Throwable ex) {
Throwable t = ex;
while (t.getCause() != null) {
t = t.getCause();
}
return t;
}
}
@@ -0,0 +1,75 @@
package com.ankurm.boot42up;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.context.ConfigurableApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The milestone and RC release notes describe spring.mvc.forwarded-headers.header-format. In the
* 4.2.0 GA jars that property is gone; the settings live under server.request.header.forwarded.*
* (strategy, naming, use-prefix) and server.forward-headers-strategy is deprecated. This sends
* both header families through each combination and records what the container believes.
*/
class ForwardedHeadersNewPropertiesTest {
private static final Map<String, Map<String, String>> HEADERS = new LinkedHashMap<>();
static {
HEADERS.put("x-forwarded", Map.of("X-Forwarded-Proto", "https", "X-Forwarded-Host", "shop.example.com",
"X-Forwarded-Port", "443"));
HEADERS.put("rfc7239", Map.of("Forwarded", "proto=https;host=shop.example.com"));
}
private static final List<List<String>> CASES = List.of(
List.of("server.request.header.forwarded.strategy=framework"),
List.of("server.request.header.forwarded.strategy=framework",
"server.request.header.forwarded.naming=x-forwarded"),
List.of("server.request.header.forwarded.strategy=framework",
"server.request.header.forwarded.naming=rfc-7239"),
List.of("server.request.header.forwarded.strategy=web-server",
"server.request.header.forwarded.naming=rfc-7239"),
List.of("server.request.header.forwarded.strategy=none"),
List.of("server.forward-headers-strategy=framework"),
List.of("server.forward-headers-strategy=framework", "spring.mvc.forwarded-headers.header-format=standard"));
@Test
void newProperties() {
Transcript t = new Transcript("19-forwarded-headers-new-properties");
if (!Transcript.is42()) {
t.line("server.request.header.forwarded.* does not exist in " + Transcript.LABEL + ": nothing to compare");
t.write();
return;
}
Map<String, String> seenByCase = new LinkedHashMap<>();
for (List<String> props : CASES) {
String label = String.join(" ", props.stream().map(p -> p.replace("server.request.header.forwarded.", "")
.replace("spring.mvc.forwarded-headers.", "mvc.")).toList());
t.line(label);
for (var e : HEADERS.entrySet()) {
try (ConfigurableApplicationContext ctx = BootRun.start(props.toArray(String[]::new))) {
Map<?, ?> seen = BootRun.whoAmI(ctx, e.getValue());
String line = String.format("scheme=%s secure=%s host=%s", seen.get("scheme"), seen.get("secure"),
seen.get("serverName"));
t.line(String.format(" %-12s %s", e.getKey(), line));
seenByCase.put(label + "/" + e.getKey(), String.valueOf(seen.get("scheme")));
}
catch (Exception ex) {
Throwable root = ex;
while (root.getCause() != null) {
root = root.getCause();
}
t.line(String.format(" %-12s FAILED: %s", e.getKey(), root.getMessage()));
}
}
}
t.write();
assertThat(seenByCase.get("strategy=framework/x-forwarded")).isEqualTo("https");
assertThat(seenByCase.get("strategy=framework/rfc7239")).isEqualTo("http");
assertThat(seenByCase.get("strategy=framework naming=rfc-7239/rfc7239")).isEqualTo("https");
assertThat(seenByCase.get("strategy=framework naming=rfc-7239/x-forwarded")).isEqualTo("http");
}
}
@@ -0,0 +1,67 @@
package com.ankurm.boot42up;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.context.ConfigurableApplicationContext;
/**
* 4.2.0-M1: "When server.forward-headers-strategy=FRAMEWORK is selected, X-Forwarded-* headers are used by
* default." Sends both header styles under each strategy and records what the container believes.
*/
class ForwardedHeadersTest {
private static final Map<String, String> X_FORWARDED = Map.of("X-Forwarded-Proto", "https",
"X-Forwarded-Host", "shop.example.com", "X-Forwarded-Port", "443");
private static final Map<String, String> RFC_7239 = Map.of("Forwarded", "proto=https;host=shop.example.com");
private static final Map<String, Map<String, String>> HEADERS = new LinkedHashMap<>();
static {
HEADERS.put("x-forwarded", X_FORWARDED);
HEADERS.put("rfc7239", RFC_7239);
}
@Test
void recordsBehaviourPerStrategy() {
Transcript t = new Transcript("18-forwarded-headers");
Map<String, Map<?, ?>> results = new LinkedHashMap<>();
for (String strategy : new String[] { "none", "native", "framework" }) {
for (var e : HEADERS.entrySet()) {
try (ConfigurableApplicationContext ctx = BootRun.start("server.forward-headers-strategy=" + strategy)) {
Map<?, ?> seen = BootRun.whoAmI(ctx, e.getValue());
String key = strategy + "/" + e.getKey();
results.put(key, seen);
t.line(String.format("%-22s scheme=%s secure=%s host=%s port=%s", key, seen.get("scheme"),
seen.get("secure"), seen.get("serverName"), seen.get("serverPort").toString().equals("443") ? "443" : "<random>"));
}
}
}
// the new 4.2 knob: which header family the FRAMEWORK strategy reads
for (var e : HEADERS.entrySet()) {
try (ConfigurableApplicationContext ctx = BootRun.start("server.forward-headers-strategy=framework",
"spring.mvc.forwarded-headers.header-format=standard")) {
Map<?, ?> seen = BootRun.whoAmI(ctx, e.getValue());
t.line(String.format("%-22s scheme=%s secure=%s host=%s port=%s", "framework+standard/" + e.getKey(),
seen.get("scheme"), seen.get("secure"), seen.get("serverName"), seen.get("serverPort").toString().equals("443") ? "443" : "<random>"));
}
}
// my first guess at the value was "forwarded"; record what the binder says about it
try (ConfigurableApplicationContext ctx = BootRun.start("server.forward-headers-strategy=framework",
"spring.mvc.forwarded-headers.header-format=forwarded")) {
t.line("header-format=forwarded -> started (property ignored)");
}
catch (Exception ex) {
Throwable root = ex;
while (root.getCause() != null) {
root = root.getCause();
}
t.line("header-format=forwarded -> " + root.getClass().getSimpleName() + ": " + root.getMessage());
}
t.write();
// a strategy of "none" must never trust either header
assertThat(results.get("none/x-forwarded").get("scheme")).isEqualTo("http");
assertThat(results.get("none/rfc7239").get("scheme")).isEqualTo("http");
}
}
@@ -0,0 +1,99 @@
package com.ankurm.boot42up;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.junit.jupiter.api.Test;
import org.springframework.boot.context.properties.bind.BindContext;
import org.springframework.boot.context.properties.bind.BindHandler;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import org.springframework.boot.kafka.autoconfigure.KafkaProperties;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Binds the new Kafka admin properties and records which of the five keys the binder actually
* consumed. On 4.2 all five bind. On 4.1.2 Boot does not complain about the unknown keys; they
* are simply never read, which is the failure mode worth knowing about.
*/
class KafkaAdminBindingTest {
private static final Map<String, String> PROPS = Map.of(
"spring.kafka.template.admin.client-id", "template-admin",
"spring.kafka.template.admin.fail-fast", "true",
"spring.kafka.listener.admin.client-id", "listener-admin",
"spring.kafka.listener.admin.fail-fast", "true",
"spring.kafka.listener.await-async-results-on-stop", "true");
@Test
void adminPropertiesBind() throws Exception {
Transcript t = new Transcript("02-kafka-admin-binding");
Set<String> consumed = new TreeSet<>();
BindHandler recorder = new BindHandler() {
@Override
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context,
Object result) {
if (context.getConfigurationProperty() != null) {
consumed.add(name.toString());
}
return result;
}
};
Binder binder = new Binder(new MapConfigurationPropertySource(PROPS));
KafkaProperties kp = binder.bind("spring.kafka", Bindable.of(KafkaProperties.class), recorder)
.orElseGet(KafkaProperties::new);
t.line("properties supplied: " + PROPS.size());
for (String key : new TreeSet<>(PROPS.keySet())) {
t.line((consumed.contains(key.substring("spring.kafka.".length())) || consumed.contains(key) ? "bound " : "IGNORED ")
+ key);
}
long bound = PROPS.keySet().stream()
.filter(k -> consumed.contains(k.substring("spring.kafka.".length())) || consumed.contains(k))
.count();
t.line("bound = " + bound + " of " + PROPS.size());
Object listener = call(kp, "getListener");
Object template = call(kp, "getTemplate");
t.line("listener.isAwaitAsyncResultsOnStop() = " + callOrAbsent(listener, "isAwaitAsyncResultsOnStop"));
t.line("template.getAdmin() = "
+ callOrAbsent(template, "getAdmin").replaceAll("@[0-9a-f]+$", ""));
if (Transcript.is42()) {
assertThat(bound).isEqualTo(5);
Object tplAdmin = call(template, "getAdmin");
Object lsnAdmin = call(listener, "getAdmin");
t.line("template admin client-id = " + call(tplAdmin, "getClientId"));
t.line("template admin fail-fast = " + call(tplAdmin, "isFailFast"));
t.line("listener admin client-id = " + call(lsnAdmin, "getClientId"));
t.line("listener admin fail-fast = " + call(lsnAdmin, "isFailFast"));
assertThat(call(tplAdmin, "getClientId")).isEqualTo("template-admin");
assertThat(call(lsnAdmin, "isFailFast")).isEqualTo(true);
}
else {
assertThat(bound).isZero();
}
t.write();
}
private static Object call(Object target, String method) throws Exception {
Method m = target.getClass().getMethod(method);
return m.invoke(target);
}
private static String callOrAbsent(Object target, String method) {
try {
return String.valueOf(call(target, method));
}
catch (NoSuchMethodException ex) {
return "no such method";
}
catch (Exception ex) {
return ex.toString();
}
}
}
@@ -0,0 +1,44 @@
package com.ankurm.boot42up;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.ldap.autoconfigure.embedded.EmbeddedLdapAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* 4.2.0-M2: spring.ldap.embedded.ssl.enabled=true without spring.ldap.embedded.ssl.bundle now
* fails at startup instead of quietly starting a plain-text listener.
*/
class LdapEmbeddedSslTest {
@Test
void sslWithoutBundle() {
Transcript t = new Transcript("03-ldap-embedded-ssl-without-bundle");
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EmbeddedLdapAutoConfiguration.class))
.withPropertyValues("spring.ldap.embedded.base-dn=dc=example,dc=org",
"spring.ldap.embedded.port=0",
"spring.ldap.embedded.ssl.enabled=true")
.run(ctx -> {
if (Transcript.is42()) {
assertThat(ctx).hasFailed();
Throwable root = ctx.getStartupFailure();
while (root.getCause() != null) {
root = root.getCause();
}
t.line("spring.ldap.embedded.ssl.enabled=true, no bundle: context FAILED to start");
t.line(root.getClass().getName());
t.line(root.getMessage());
}
else {
assertThat(ctx).hasNotFailed();
t.line("spring.ldap.embedded.ssl.enabled=true, no bundle: context STARTED");
t.line("embedded server beans: "
+ ctx.getBeanNamesForType(com.unboundid.ldap.listener.InMemoryDirectoryServer.class).length);
}
});
t.write();
}
}
@@ -0,0 +1,44 @@
package com.ankurm.boot42up;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureRestTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.web.servlet.client.RestTestClient;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The migrated forms of the two deprecated 4.2 types: RestClient.Builder (via PingClient) in
* place of RestTemplateBuilder, and RestTestClient in place of TestRestTemplate. Both run on
* 4.1.3 and on 4.2.0, so the migration can be done before the upgrade.
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureRestTestClient
class MigratedClientsTest {
@LocalServerPort
int port;
@Autowired
PingClient pingClient;
@Autowired
RestTestClient restTestClient;
@Test
void restClientAndRestTestClient() {
Transcript t = new Transcript("13-migrated-clients");
String viaRestClient = this.pingClient.fetch("http://localhost:" + this.port + "/hello/rest-client");
t.line("RestClient.Builder GET /hello/rest-client -> " + viaRestClient);
assertThat(viaRestClient).isEqualTo("hello rest-client");
String[] viaTestClient = new String[1];
this.restTestClient.get().uri("/hello/rest-test-client").exchange().expectStatus().isOk()
.expectBody(String.class).value(body -> viaTestClient[0] = body);
t.line("RestTestClient GET /hello/rest-test-client -> " + viaTestClient[0]);
assertThat(viaTestClient[0]).isEqualTo("hello rest-test-client");
t.write();
}
}
@@ -0,0 +1,58 @@
package com.ankurm.boot42up;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* 4.2.0-RC1: spring.properties.migrator.fail lets the migrator stop the application instead of
* only logging. 4.1.3 has no such switch, so the baseline run only records that.
*/
class MigratorFailSwitchTest {
@Configuration(proxyBeanMethods = false)
static class Empty {
}
private static Map<String, Object> props(String fail) {
return Map.of("spring.mvc.pathmatch.matching-strategy", "path_pattern_parser",
"server.tomcat.use-relative-redirects", "false", "spring.properties.migrator.fail", fail);
}
private static String outcome(String fail) {
SpringApplication app = new SpringApplication(Empty.class);
app.setWebApplicationType(WebApplicationType.NONE);
app.setDefaultProperties(props(fail));
try {
app.run().close();
return "application STARTED";
}
catch (Exception ex) {
Throwable root = ex;
while (root.getCause() != null) {
root = root.getCause();
}
return "application FAILED to start: " + root.getClass().getSimpleName();
}
}
@Test
void failSwitch() {
Transcript t = new Transcript("17-migrator-fail-switch");
// the test keys: one error-level (removed key) and one warning-level (renamed key)
for (String value : new String[] { "never", "on-error", "on-warning" }) {
String result = outcome(value);
t.line(String.format("spring.properties.migrator.fail=%-10s -> %s", value, result));
if (Transcript.is42()) {
assertThat(result.startsWith("application FAILED")).isEqualTo(!value.equals("never"));
}
}
t.write();
}
}
@@ -0,0 +1,55 @@
package com.ankurm.boot42up;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Starts an empty application with the property keys 4.2 relocated or deprecated and captures
* what spring-boot-properties-migrator prints. The keys come from the 4.2.0-M2 configuration
* changelog.
*/
@ExtendWith(OutputCaptureExtension.class)
class MigratorTest {
@Configuration(proxyBeanMethods = false)
static class Empty {
}
@Test
void migratorReport(CapturedOutput output) {
Transcript t = new Transcript("04-properties-migrator-report");
SpringApplication app = new SpringApplication(Empty.class);
app.setWebApplicationType(WebApplicationType.NONE);
app.setDefaultProperties(java.util.Map.of(
"server.tomcat.use-relative-redirects", "false",
"server.tomcat.redirect-context-root", "false",
"server.tomcat.additional-tld-skip-patterns", "*.jar",
"spring.mvc.pathmatch.matching-strategy", "path_pattern_parser",
"management.metrics.observations.ignored-meters", "http.server.requests",
"server.forward-headers-strategy", "framework"));
app.run().close();
boolean any = false;
for (String line : output.getAll().split("\n")) {
String s = line.strip();
if (s.startsWith("Property source") || s.startsWith("Key:") || s.startsWith("Reason:")
|| s.startsWith("Replacement:") || s.contains("configuration keys")
|| s.contains("have been renamed") || s.contains("deprecated") && s.contains("configuration")
|| s.contains("no longer supported") || s.contains("been removed")) {
t.line(s);
any = true;
}
}
if (Transcript.is42()) {
assertThat(output.getAll()).contains("server.tomcat.servlet.use-relative-redirects");
assertThat(any).isTrue();
}
t.write();
}
}
@@ -0,0 +1,64 @@
package com.ankurm.boot42up;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.ldap.autoconfigure.LdapAutoConfiguration;
import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.ldap.core.support.LdapContextSource;
import static org.assertj.core.api.Assertions.assertThat;
/**
* 4.2.0-RC2 upgrade note: an SSL bundle that sets options.ciphers or options.enabled-protocols
* used to be accepted and silently ignored by the LDAP client; now startup fails. The
* spring.ldap.ssl.bundle property is new in 4.2, so there is no 4.1.3 behaviour to compare to.
*/
class SslBundleOptionsTest {
private static final String TRUSTSTORE = "spring.ssl.bundle.jks.demo.truststore.";
private ApplicationContextRunner runner() {
return new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(SslAutoConfiguration.class, LdapAutoConfiguration.class))
.withPropertyValues("spring.ldap.urls=ldaps://localhost:636", "spring.ldap.ssl.bundle=demo",
TRUSTSTORE + "location=classpath:demo-trust.p12", TRUSTSTORE + "password=changeit",
TRUSTSTORE + "type=PKCS12");
}
@Test
void bundleOptionsOnLdapClient() {
Transcript t = new Transcript("08-ssl-bundle-options-ldap");
if (!Transcript.is42()) {
t.line("spring.ldap.ssl.bundle does not exist in " + Transcript.LABEL + ": nothing to compare");
t.write();
return;
}
runner().run(ctx -> {
assertThat(ctx).hasNotFailed();
t.line("bundle without options: context STARTED, LdapContextSource beans: "
+ ctx.getBeansOfType(LdapContextSource.class).size());
});
runner().withPropertyValues("spring.ssl.bundle.jks.demo.options.ciphers=TLS_AES_128_GCM_SHA256")
.run(ctx -> {
assertThat(ctx).hasFailed();
t.line("bundle with options.ciphers: context FAILED to start");
t.line(" " + rootCause(ctx.getStartupFailure()).getMessage());
});
runner().withPropertyValues("spring.ssl.bundle.jks.demo.options.enabled-protocols=TLSv1.3")
.run(ctx -> {
assertThat(ctx).hasFailed();
t.line("bundle with options.enabled-protocols: context FAILED to start");
t.line(" " + rootCause(ctx.getStartupFailure()).getMessage());
});
t.write();
}
private static Throwable rootCause(Throwable ex) {
Throwable t = ex;
while (t.getCause() != null) {
t = t.getCause();
}
return t;
}
}
@@ -0,0 +1,45 @@
package com.ankurm.boot42up;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
/**
* Collects lines and writes output/NN-name.txt (or NN-name-on-4.1.2.txt when run against the
* 4.1 baseline). The test asserts the same values it writes, so every figure quoted in the
* article is an assertion that fails the build when it stops being true.
*/
final class Transcript {
static final String LABEL = System.getProperty("boot.label", "4.2.0");
static boolean is42() {
return LABEL.startsWith("4.2");
}
private final List<String> lines = new ArrayList<>();
private final Path file;
Transcript(String name) {
String suffix = is42() ? "" : "-on-" + LABEL;
this.file = Path.of("output", name + suffix + ".txt");
line("# " + name + " (Spring Boot " + LABEL + ", JDK " + Runtime.version().feature() + ")");
}
Transcript line(String s) {
lines.add(s);
return this;
}
void write() {
try {
Files.createDirectories(file.getParent());
Files.write(file, lines);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
}
Binary file not shown.