diff --git a/README.md b/README.md index 32e93be..7853a2e 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,8 @@ files. | [`file-transfer/`](file-transfer) | [File Upload and Download in Spring Boot 4: Multipart, Streaming and S3 Presigned URLs](https://ankurm.com/file-upload-download-spring-boot-4-multipart-streaming-s3-presigned-urls/) | multipart limits enforced by Tomcat (and ignored by `MockMvc`), the client-controlled filename, `Range` downloads, a 200 MB download and 150 MB upload under `-Xmx64m`, and S3 presigned URLs checked against a local SigV4 verifier (not a real S3) | | [`project-structure/`](project-structure) | [Spring Boot Project Structure: Package-by-Layer vs Package-by-Feature](https://ankurm.com/spring-boot-project-structure/) | the same application written package-by-layer and package-by-feature with one HTTP API, the real source trees, 9 of 9 types public by layer vs 3 of 15 by feature, and the `javac` error that makes a feature boundary a compiler rule instead of a convention | | [`crud-mysql/`](crud-mysql) | [Spring Boot CRUD REST API with MySQL and Spring Data JPA](https://ankurm.com/spring-boot-crud-rest-api-mysql/) | a complete book API on a real MySQL 8.4.6 server with Flyway owning the schema and Hibernate set to `validate`, `ProblemDetail` errors with per-field validation messages, a duplicate ISBN caught by the database's unique key and mapped to `409` on create and on update, MySQL's own `Duplicate entry` message, and the SQL behind every request | -| [`boot42-rc1-checklist/`](boot42-rc1-checklist) | [Spring Framework 7.1 and Spring Boot 4.2: What's Coming and How to Prepare](https://ankurm.com/spring-boot-4-2-spring-framework-7-1-upgrade-checklist/) | each 4.2 milestone change run on 4.2.0-RC1 and on 4.1.2: `@DefaultValue` placeholders resolved, five new Kafka admin keys that 4.1.2 silently ignores, embedded LDAP SSL failing without a bundle, the properties migrator's real report (and the removed key it misses), and the `RestTemplate` removal warnings from the compiler | +| [`boot42-rc1-checklist/`](boot42-rc1-checklist) | [Spring Framework 7.1 and Spring Boot 4.2: What's Coming and How to Prepare](https://ankurm.com/spring-boot-4-2-spring-framework-7-1-upgrade-checklist/) | **superseded by [`boot42-upgrade/`](boot42-upgrade); kept because older posts link to it.** Each 4.2 milestone change run on 4.2.0-RC1 and on 4.1.2: `@DefaultValue` placeholders resolved, five new Kafka admin keys that 4.1.2 silently ignores, embedded LDAP SSL failing without a bundle, the properties migrator's real report (and the removed key it misses), and the `RestTemplate` removal warnings from the compiler | +| [`boot42-upgrade/`](boot42-upgrade) | [Spring Boot 4.2 GA: What's New, What's Deprecated and the 4.1 to 4.2 Upgrade Checklist](https://ankurm.com/spring-boot-4-2-spring-framework-7-1-upgrade-checklist/) | the 4.2.0 GA re-run of the RC1 checklist against 4.1.3: `@DefaultValue` placeholders, Kafka admin keys that 4.1.3 silently ignores, embedded LDAP SSL without a bundle, SSL-bundle `options` rejected by the LDAP client, the migrator's real report and its new `spring.properties.migrator.fail` switch, compiler `[removal]` warnings for `RestTemplate`, `TestRestTemplate` and the Pulsar classes, `open-telemetry` convention now starting, plus defaults, buildpack builder constants and BOM versions read straight from the 4.1.3 and 4.2.0 artifacts | | [`boot42-otel/`](boot42-otel) | [Spring Boot 4.2 OpenTelemetry: Semantic Conventions, Shared OTLP Settings and MDC Keys](https://ankurm.com/spring-boot-4-2-opentelemetry-semantic-conventions-shared-otlp-mdc/) | one request measured under each `management.observations.conventions` value (the documented `open-telemetry` fails to start on RC1, `opentelemetry` works), meter, span and Prometheus names before and after, `management.opentelemetry.otlp.*` verified against a local OTLP receiver (paths, merged headers, gzip, per-signal overrides), custom MDC keys, and the LongTaskTimer that is no longer on by default | | [`boot4-migration/`](boot4-migration) | [Spring Boot 3 to 4 Migration Guide (Updated for 4.1 and 4.2)](https://ankurm.com/spring-boot-3-to-4-migration-guide/) | one Boot 3.5.16 service migrated to 4.1.2 with the real failures captured at each step: 12 javac errors from a version bump, a start-up failure from a missing `spring-boot-starter-restclient`, Flyway silently not running without `spring-boot-starter-flyway`, removed `logging.file.*` keys silently ignored, Jackson 3 sorting bean properties, liveness/readiness groups appearing, and a `@Mock` field that is `null` without `MockitoExtension` | | [`startup-runners/`](startup-runners) | [CommandLineRunner vs ApplicationRunner vs ApplicationReadyEvent in Spring Boot 4](https://ankurm.com/commandlinerunner-vs-applicationrunner-vs-applicationreadyevent-spring-boot-4/) | the real order of every startup hook printed from a running app, one shared sort for both runner types with arbitrary ties, runner failure vs `ApplicationReadyEvent` listener failure (exit codes, `ApplicationFailedEvent`), a blocking runner holding readiness at 503, `SmartLifecycle` phases, and which hooks `@SpringBootTest` and `@WebMvcTest` run | diff --git a/boot42-upgrade/README.md b/boot42-upgrade/README.md new file mode 100644 index 0000000..5ba0979 --- /dev/null +++ b/boot42-upgrade/README.md @@ -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. diff --git a/boot42-upgrade/output/01-default-value-placeholders-on-4.1.3.txt b/boot42-upgrade/output/01-default-value-placeholders-on-4.1.3.txt new file mode 100644 index 0000000..49abae7 --- /dev/null +++ b/boot42-upgrade/output/01-default-value-placeholders-on-4.1.3.txt @@ -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}" diff --git a/boot42-upgrade/output/01-default-value-placeholders.txt b/boot42-upgrade/output/01-default-value-placeholders.txt new file mode 100644 index 0000000..d22e473 --- /dev/null +++ b/boot42-upgrade/output/01-default-value-placeholders.txt @@ -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 diff --git a/boot42-upgrade/output/02-kafka-admin-binding-on-4.1.3.txt b/boot42-upgrade/output/02-kafka-admin-binding-on-4.1.3.txt new file mode 100644 index 0000000..32d2623 --- /dev/null +++ b/boot42-upgrade/output/02-kafka-admin-binding-on-4.1.3.txt @@ -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 diff --git a/boot42-upgrade/output/02-kafka-admin-binding.txt b/boot42-upgrade/output/02-kafka-admin-binding.txt new file mode 100644 index 0000000..fa07e72 --- /dev/null +++ b/boot42-upgrade/output/02-kafka-admin-binding.txt @@ -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 diff --git a/boot42-upgrade/output/03-ldap-embedded-ssl-without-bundle-on-4.1.3.txt b/boot42-upgrade/output/03-ldap-embedded-ssl-without-bundle-on-4.1.3.txt new file mode 100644 index 0000000..e7405e0 --- /dev/null +++ b/boot42-upgrade/output/03-ldap-embedded-ssl-without-bundle-on-4.1.3.txt @@ -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 diff --git a/boot42-upgrade/output/03-ldap-embedded-ssl-without-bundle.txt b/boot42-upgrade/output/03-ldap-embedded-ssl-without-bundle.txt new file mode 100644 index 0000000..d6a92d7 --- /dev/null +++ b/boot42-upgrade/output/03-ldap-embedded-ssl-without-bundle.txt @@ -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 diff --git a/boot42-upgrade/output/04-properties-migrator-report-on-4.1.3.txt b/boot42-upgrade/output/04-properties-migrator-report-on-4.1.3.txt new file mode 100644 index 0000000..151e904 --- /dev/null +++ b/boot42-upgrade/output/04-properties-migrator-report-on-4.1.3.txt @@ -0,0 +1 @@ +# 04-properties-migrator-report (Spring Boot 4.1.3, JDK 25) diff --git a/boot42-upgrade/output/04-properties-migrator-report.txt b/boot42-upgrade/output/04-properties-migrator-report.txt new file mode 100644 index 0000000..2b20a69 --- /dev/null +++ b/boot42-upgrade/output/04-properties-migrator-report.txt @@ -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 diff --git a/boot42-upgrade/output/05-resttemplate-compiler-warnings-on-4.1.3.txt b/boot42-upgrade/output/05-resttemplate-compiler-warnings-on-4.1.3.txt new file mode 100644 index 0000000..9790a04 --- /dev/null +++ b/boot42-upgrade/output/05-resttemplate-compiler-warnings-on-4.1.3.txt @@ -0,0 +1,3 @@ +# 05-resttemplate-compiler-warnings (Spring Boot 4.1.3, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -d target/broken src/broken/UsesRestTemplate.java +exit: 0 diff --git a/boot42-upgrade/output/05-resttemplate-compiler-warnings.txt b/boot42-upgrade/output/05-resttemplate-compiler-warnings.txt new file mode 100644 index 0000000..ceb4b3a --- /dev/null +++ b/boot42-upgrade/output/05-resttemplate-compiler-warnings.txt @@ -0,0 +1,10 @@ +# 05-resttemplate-compiler-warnings (Spring Boot 4.2.0, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -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 diff --git a/boot42-upgrade/output/06-testresttemplate-compiler-warnings-on-4.1.3.txt b/boot42-upgrade/output/06-testresttemplate-compiler-warnings-on-4.1.3.txt new file mode 100644 index 0000000..3a3aa59 --- /dev/null +++ b/boot42-upgrade/output/06-testresttemplate-compiler-warnings-on-4.1.3.txt @@ -0,0 +1,3 @@ +# 06-testresttemplate-compiler-warnings (Spring Boot 4.1.3, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -d target/broken src/broken/UsesTestRestTemplate.java +exit: 0 diff --git a/boot42-upgrade/output/06-testresttemplate-compiler-warnings.txt b/boot42-upgrade/output/06-testresttemplate-compiler-warnings.txt new file mode 100644 index 0000000..455d7e4 --- /dev/null +++ b/boot42-upgrade/output/06-testresttemplate-compiler-warnings.txt @@ -0,0 +1,7 @@ +# 06-testresttemplate-compiler-warnings (Spring Boot 4.2.0, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -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 diff --git a/boot42-upgrade/output/07-pulsar-compiler-warnings-on-4.1.3.txt b/boot42-upgrade/output/07-pulsar-compiler-warnings-on-4.1.3.txt new file mode 100644 index 0000000..16e905d --- /dev/null +++ b/boot42-upgrade/output/07-pulsar-compiler-warnings-on-4.1.3.txt @@ -0,0 +1,3 @@ +# 07-pulsar-compiler-warnings (Spring Boot 4.1.3, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -d target/broken src/broken/UsesPulsarProperties.java +exit: 0 diff --git a/boot42-upgrade/output/07-pulsar-compiler-warnings.txt b/boot42-upgrade/output/07-pulsar-compiler-warnings.txt new file mode 100644 index 0000000..5c98f44 --- /dev/null +++ b/boot42-upgrade/output/07-pulsar-compiler-warnings.txt @@ -0,0 +1,10 @@ +# 07-pulsar-compiler-warnings (Spring Boot 4.2.0, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -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 diff --git a/boot42-upgrade/output/08-ssl-bundle-options-ldap-on-4.1.3.txt b/boot42-upgrade/output/08-ssl-bundle-options-ldap-on-4.1.3.txt new file mode 100644 index 0000000..b2f5745 --- /dev/null +++ b/boot42-upgrade/output/08-ssl-bundle-options-ldap-on-4.1.3.txt @@ -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 diff --git a/boot42-upgrade/output/08-ssl-bundle-options-ldap.txt b/boot42-upgrade/output/08-ssl-bundle-options-ldap.txt new file mode 100644 index 0000000..3360ba3 --- /dev/null +++ b/boot42-upgrade/output/08-ssl-bundle-options-ldap.txt @@ -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 diff --git a/boot42-upgrade/output/09-conventions-spellings-on-4.1.3.txt b/boot42-upgrade/output/09-conventions-spellings-on-4.1.3.txt new file mode 100644 index 0000000..3007821 --- /dev/null +++ b/boot42-upgrade/output/09-conventions-spellings-on-4.1.3.txt @@ -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] diff --git a/boot42-upgrade/output/09-conventions-spellings.txt b/boot42-upgrade/output/09-conventions-spellings.txt new file mode 100644 index 0000000..e4b7999 --- /dev/null +++ b/boot42-upgrade/output/09-conventions-spellings.txt @@ -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] diff --git a/boot42-upgrade/output/10-config-defaults.txt b/boot42-upgrade/output/10-config-defaults.txt new file mode 100644 index 0000000..771e545 --- /dev/null +++ b/boot42-upgrade/output/10-config-defaults.txt @@ -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) diff --git a/boot42-upgrade/output/11-buildpack-defaults.txt b/boot42-upgrade/output/11-buildpack-defaults.txt new file mode 100644 index 0000000..fd14732 --- /dev/null +++ b/boot42-upgrade/output/11-buildpack-defaults.txt @@ -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"; diff --git a/boot42-upgrade/output/12-bom-versions.txt b/boot42-upgrade/output/12-bom-versions.txt new file mode 100644 index 0000000..b94a095 --- /dev/null +++ b/boot42-upgrade/output/12-bom-versions.txt @@ -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 diff --git a/boot42-upgrade/output/13-migrated-clients-on-4.1.3.txt b/boot42-upgrade/output/13-migrated-clients-on-4.1.3.txt new file mode 100644 index 0000000..d66ef4d --- /dev/null +++ b/boot42-upgrade/output/13-migrated-clients-on-4.1.3.txt @@ -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 diff --git a/boot42-upgrade/output/13-migrated-clients.txt b/boot42-upgrade/output/13-migrated-clients.txt new file mode 100644 index 0000000..df51944 --- /dev/null +++ b/boot42-upgrade/output/13-migrated-clients.txt @@ -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 diff --git a/boot42-upgrade/output/14-migrated-client-compiler-on-4.1.3.txt b/boot42-upgrade/output/14-migrated-client-compiler-on-4.1.3.txt new file mode 100644 index 0000000..42c79ee --- /dev/null +++ b/boot42-upgrade/output/14-migrated-client-compiler-on-4.1.3.txt @@ -0,0 +1,3 @@ +# 14-migrated-client-compiler (Spring Boot 4.1.3, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -d target/broken src/main/java/com/ankurm/boot42up/PingClient.java +exit: 0 diff --git a/boot42-upgrade/output/14-migrated-client-compiler.txt b/boot42-upgrade/output/14-migrated-client-compiler.txt new file mode 100644 index 0000000..7dcc7bf --- /dev/null +++ b/boot42-upgrade/output/14-migrated-client-compiler.txt @@ -0,0 +1,3 @@ +# 14-migrated-client-compiler (Spring Boot 4.2.0, JDK 25.0.5.1) +$ javac -Xlint:deprecation -cp -d target/broken src/main/java/com/ankurm/boot42up/PingClient.java +exit: 0 diff --git a/boot42-upgrade/output/15-amqp-starters.txt b/boot42-upgrade/output/15-amqp-starters.txt new file mode 100644 index 0000000..b11cd67 --- /dev/null +++ b/boot42-upgrade/output/15-amqp-starters.txt @@ -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 diff --git a/boot42-upgrade/output/16-migrator-fail-switch.txt b/boot42-upgrade/output/16-migrator-fail-switch.txt new file mode 100644 index 0000000..6d23d4a --- /dev/null +++ b/boot42-upgrade/output/16-migrator-fail-switch.txt @@ -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 diff --git a/boot42-upgrade/output/17-migrator-fail-switch-on-4.1.3.txt b/boot42-upgrade/output/17-migrator-fail-switch-on-4.1.3.txt new file mode 100644 index 0000000..d250912 --- /dev/null +++ b/boot42-upgrade/output/17-migrator-fail-switch-on-4.1.3.txt @@ -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 diff --git a/boot42-upgrade/output/17-migrator-fail-switch.txt b/boot42-upgrade/output/17-migrator-fail-switch.txt new file mode 100644 index 0000000..efb5717 --- /dev/null +++ b/boot42-upgrade/output/17-migrator-fail-switch.txt @@ -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 diff --git a/boot42-upgrade/output/18-forwarded-headers-on-4.1.3.txt b/boot42-upgrade/output/18-forwarded-headers-on-4.1.3.txt new file mode 100644 index 0000000..535a91f --- /dev/null +++ b/boot42-upgrade/output/18-forwarded-headers-on-4.1.3.txt @@ -0,0 +1,10 @@ +# 18-forwarded-headers (Spring Boot 4.1.3, JDK 25) +none/x-forwarded scheme=http secure=false host=localhost port= +none/rfc7239 scheme=http secure=false host=localhost port= +native/x-forwarded scheme=https secure=true host=shop.example.com port=443 +native/rfc7239 scheme=http secure=false host=localhost port= +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) diff --git a/boot42-upgrade/output/18-forwarded-headers.txt b/boot42-upgrade/output/18-forwarded-headers.txt new file mode 100644 index 0000000..f2baa77 --- /dev/null +++ b/boot42-upgrade/output/18-forwarded-headers.txt @@ -0,0 +1,10 @@ +# 18-forwarded-headers (Spring Boot 4.2.0, JDK 25) +none/x-forwarded scheme=http secure=false host=localhost port= +none/rfc7239 scheme=http secure=false host=localhost port= +native/x-forwarded scheme=https secure=true host=shop.example.com port=443 +native/rfc7239 scheme=http secure=false host=localhost port= +framework/x-forwarded scheme=https secure=true host=shop.example.com port=443 +framework/rfc7239 scheme=http secure=false host=localhost port= +framework+standard/x-forwarded scheme=https secure=true host=shop.example.com port=443 +framework+standard/rfc7239 scheme=http secure=false host=localhost port= +header-format=forwarded -> started (property ignored) diff --git a/boot42-upgrade/output/19-forwarded-headers-new-properties-on-4.1.3.txt b/boot42-upgrade/output/19-forwarded-headers-new-properties-on-4.1.3.txt new file mode 100644 index 0000000..12c9272 --- /dev/null +++ b/boot42-upgrade/output/19-forwarded-headers-new-properties-on-4.1.3.txt @@ -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 diff --git a/boot42-upgrade/output/19-forwarded-headers-new-properties.txt b/boot42-upgrade/output/19-forwarded-headers-new-properties.txt new file mode 100644 index 0000000..fe6621f --- /dev/null +++ b/boot42-upgrade/output/19-forwarded-headers-new-properties.txt @@ -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 diff --git a/boot42-upgrade/output/20-migrator-without-actuator.txt b/boot42-upgrade/output/20-migrator-without-actuator.txt new file mode 100644 index 0000000..a1b7a96 --- /dev/null +++ b/boot42-upgrade/output/20-migrator-without-actuator.txt @@ -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 diff --git a/boot42-upgrade/pom-41.xml b/boot42-upgrade/pom-41.xml new file mode 100644 index 0000000..f43abf9 --- /dev/null +++ b/boot42-upgrade/pom-41.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 4.1.3 + + + + com.ankurm + boot42-upgrade + 1.0.0 + boot42-upgrade + Spring Boot 4.2.0 upgrade checklist: each claim run against 4.2.0 and 4.1.3 + + + 25 + 4.1.3 + + + + + org.springframework.boot + spring-boot-starter-webmvc + + + org.springframework.boot + spring-boot-starter-restclient + + + org.springframework.boot + spring-boot-starter-kafka + + + org.springframework.boot + spring-boot-starter-ldap + + + com.unboundid + unboundid-ldapsdk + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-opentelemetry + + + org.springframework.boot + spring-boot-resttestclient + test + + + org.springframework.boot + spring-boot-properties-migrator + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + maven-surefire-plugin + + + ${boot.label} + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/boot42-upgrade/pom.xml b/boot42-upgrade/pom.xml new file mode 100644 index 0000000..f7c13b0 --- /dev/null +++ b/boot42-upgrade/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 4.2.0 + + + + com.ankurm + boot42-upgrade + 1.0.0 + boot42-upgrade + Spring Boot 4.2.0 GA upgrade checklist: each claim run against 4.2.0 and 4.1.3 + + + 25 + 4.2.0 + + + + + org.springframework.boot + spring-boot-starter-webmvc + + + org.springframework.boot + spring-boot-starter-restclient + + + org.springframework.boot + spring-boot-starter-kafka + + + org.springframework.boot + spring-boot-starter-ldap + + + com.unboundid + unboundid-ldapsdk + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-opentelemetry + + + org.springframework.boot + spring-boot-resttestclient + test + + + org.springframework.boot + spring-boot-properties-migrator + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + maven-surefire-plugin + + + ${boot.label} + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/boot42-upgrade/scripts/compile-broken.sh b/boot42-upgrade/scripts/compile-broken.sh new file mode 100755 index 0000000..06f5e45 --- /dev/null +++ b/boot42-upgrade/scripts/compile-broken.sh @@ -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 '' "$POM" | sed -E 's/.*(.*)<\/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() { # + 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 diff --git a/boot42-upgrade/scripts/migrator-without-actuator.sh b/boot42-upgrade/scripts/migrator-without-actuator.sh new file mode 100755 index 0000000..8e4239d --- /dev/null +++ b/boot42-upgrade/scripts/migrator-without-actuator.sh @@ -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 diff --git a/boot42-upgrade/scripts/probe-jars.sh b/boot42-upgrade/scripts/probe-jars.sh new file mode 100755 index 0000000..2881617 --- /dev/null +++ b/boot42-upgrade/scripts/probe-jars.sh @@ -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 diff --git a/boot42-upgrade/scripts/run-all.sh b/boot42-upgrade/scripts/run-all.sh new file mode 100755 index 0000000..d944ac4 --- /dev/null +++ b/boot42-upgrade/scripts/run-all.sh @@ -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/" diff --git a/boot42-upgrade/src/broken/UsesPulsarProperties.java b/boot42-upgrade/src/broken/UsesPulsarProperties.java new file mode 100644 index 0000000..e727cc0 --- /dev/null +++ b/boot42-upgrade/src/broken/UsesPulsarProperties.java @@ -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(); + } +} diff --git a/boot42-upgrade/src/broken/UsesRestTemplate.java b/boot42-upgrade/src/broken/UsesRestTemplate.java new file mode 100644 index 0000000..2cdf318 --- /dev/null +++ b/boot42-upgrade/src/broken/UsesRestTemplate.java @@ -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); + } +} diff --git a/boot42-upgrade/src/broken/UsesTestRestTemplate.java b/boot42-upgrade/src/broken/UsesTestRestTemplate.java new file mode 100644 index 0000000..0013134 --- /dev/null +++ b/boot42-upgrade/src/broken/UsesTestRestTemplate.java @@ -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); + } +} diff --git a/boot42-upgrade/src/main/java/com/ankurm/boot42up/DemoPort.java b/boot42-upgrade/src/main/java/com/ankurm/boot42up/DemoPort.java new file mode 100644 index 0000000..9a4e065 --- /dev/null +++ b/boot42-upgrade/src/main/java/com/ankurm/boot42up/DemoPort.java @@ -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) { +} diff --git a/boot42-upgrade/src/main/java/com/ankurm/boot42up/DemoProperties.java b/boot42-upgrade/src/main/java/com/ankurm/boot42up/DemoProperties.java new file mode 100644 index 0000000..c98afce --- /dev/null +++ b/boot42-upgrade/src/main/java/com/ankurm/boot42up/DemoProperties.java @@ -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) { +} diff --git a/boot42-upgrade/src/main/java/com/ankurm/boot42up/HelloController.java b/boot42-upgrade/src/main/java/com/ankurm/boot42up/HelloController.java new file mode 100644 index 0000000..69a69d7 --- /dev/null +++ b/boot42-upgrade/src/main/java/com/ankurm/boot42up/HelloController.java @@ -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; + } +} diff --git a/boot42-upgrade/src/main/java/com/ankurm/boot42up/PingClient.java b/boot42-upgrade/src/main/java/com/ankurm/boot42up/PingClient.java new file mode 100644 index 0000000..310bee7 --- /dev/null +++ b/boot42-upgrade/src/main/java/com/ankurm/boot42up/PingClient.java @@ -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); + } +} diff --git a/boot42-upgrade/src/main/java/com/ankurm/boot42up/UpgradeApplication.java b/boot42-upgrade/src/main/java/com/ankurm/boot42up/UpgradeApplication.java new file mode 100644 index 0000000..c9e2dd8 --- /dev/null +++ b/boot42-upgrade/src/main/java/com/ankurm/boot42up/UpgradeApplication.java @@ -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); + } +} diff --git a/boot42-upgrade/src/main/java/com/ankurm/boot42up/WhoAmIController.java b/boot42-upgrade/src/main/java/com/ankurm/boot42up/WhoAmIController.java new file mode 100644 index 0000000..ea04f66 --- /dev/null +++ b/boot42-upgrade/src/main/java/com/ankurm/boot42up/WhoAmIController.java @@ -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; + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/BootRun.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/BootRun.java new file mode 100644 index 0000000..fc40f3c --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/BootRun.java @@ -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); + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/ConventionSpellingsTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/ConventionSpellingsTest.java new file mode 100644 index 0000000..723e4a1 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/ConventionSpellingsTest.java @@ -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"); + } + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/DefaultValuePlaceholderTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/DefaultValuePlaceholderTest.java new file mode 100644 index 0000000..b64ff9c --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/DefaultValuePlaceholderTest.java @@ -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; + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/ForwardedHeadersNewPropertiesTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/ForwardedHeadersNewPropertiesTest.java new file mode 100644 index 0000000..c3154d2 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/ForwardedHeadersNewPropertiesTest.java @@ -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"); + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/ForwardedHeadersTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/ForwardedHeadersTest.java new file mode 100644 index 0000000..e910148 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/ForwardedHeadersTest.java @@ -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"); + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/KafkaAdminBindingTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/KafkaAdminBindingTest.java new file mode 100644 index 0000000..6ba2200 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/KafkaAdminBindingTest.java @@ -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(); + } + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/LdapEmbeddedSslTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/LdapEmbeddedSslTest.java new file mode 100644 index 0000000..5eb1be5 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/LdapEmbeddedSslTest.java @@ -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(); + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratedClientsTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratedClientsTest.java new file mode 100644 index 0000000..1c53ca6 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratedClientsTest.java @@ -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(); + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratorFailSwitchTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratorFailSwitchTest.java new file mode 100644 index 0000000..95b3203 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratorFailSwitchTest.java @@ -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(); + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratorTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratorTest.java new file mode 100644 index 0000000..ff2ee15 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/MigratorTest.java @@ -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(); + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/SslBundleOptionsTest.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/SslBundleOptionsTest.java new file mode 100644 index 0000000..d4afe61 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/SslBundleOptionsTest.java @@ -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; + } +} diff --git a/boot42-upgrade/src/test/java/com/ankurm/boot42up/Transcript.java b/boot42-upgrade/src/test/java/com/ankurm/boot42up/Transcript.java new file mode 100644 index 0000000..bd96d54 --- /dev/null +++ b/boot42-upgrade/src/test/java/com/ankurm/boot42up/Transcript.java @@ -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); + } + } +} diff --git a/boot42-upgrade/src/test/resources/demo-trust.p12 b/boot42-upgrade/src/test/resources/demo-trust.p12 new file mode 100644 index 0000000..bec2d51 Binary files /dev/null and b/boot42-upgrade/src/test/resources/demo-trust.p12 differ