Video in progress

Staff 🌱 Spring

How do you safely modernize an old Spring project on Java 8 with XML configuration?

I don't do a big rewrite, I go step by step: first lock in the current behavior with tests, then upgrade the build and the Java version, gradually replace XML with Java configuration, move to Spring Boot, and release each step separately. I run the work in parallel with new features and show the business the benefit.

📖 Answer

  1. A safety net. An old project will have few tests. First write "characterization" tests for the main flows: they record how the system behaves right now (at the HTTP level, with a real database). Without them every change is a gamble.

  2. Build and environment: upgrade Maven/Gradle, sort out dependencies with a BOM, CI, remove unused libraries.

  3. Java: 8 → 11 → 17 (or straight to 17). Removed modules like javax.xml.bind and reflection restrictions show up. OpenRewrite recipes do most of the work.

  4. Spring: 4 → 5.3, which still works with javax and XML. Then to 6 / Boot 3 with jakarta.

  5. Configuration: gradually move the XML beans to @Configuration + @Import. The two work together through @ImportResource("classpath:legacy.xml"). One PR per section.

  6. Spring Boot: first add Boot as a shell that imports the XML, then move the DataSource, transactions and web to auto-configuration. Moving from WAR to jar also changes the deploy process, so plan it with the ops team.

  7. Observation: after each stage, compare the error rate, latency and memory with the old version.

On the organizational side, a "big bang" (freezing the code for 6 months) almost always fails. Explain it to the business in terms of risk: unsupported versions, no security patches, hard to hire new developers. Each stage should have a clear "done" criterion.