Modernizing a Legacy Java Application With OpenRewrite: What We Automated and What We Didn't
A practical look at OpenRewrite for large-scale Java/Spring refactoring, including automated transformations, SQL limitations, and runtime issues.
OpenRewrite in a Real Enterprise Migration
Recently, we modernized a 9-year-old enterprise application that involved two major changes happening together:
- Java 8 → Java 25
- Spring Boot 2.3.3 → Spring Boot 3.3.4
At the same time, we were also moving the application from a monolithic architecture toward microservices.
One of the biggest challenges was the sheer volume of source-code changes. With Java 17 being the minimum required baseline for Spring Boot 3 and major namespace changes such as javax.* → jakarta.*, manually modifying a large codebase would have been time-consuming and risky.
We decided to use OpenRewrite to automate the mechanical parts of the migration.
The result was significant:
2,384 Java files were refactored in minutes.
The manual effort that we estimated at roughly 5–7 days was reduced to automated transformation followed by code review and testing.
But the most interesting part wasn't simply how much OpenRewrite changed. It was understanding what it could automate, what it couldn't, and where human judgment was still required.
What Is OpenRewrite?
OpenRewrite is an automated refactoring framework designed to transform source code using recipes.
Instead of manually searching through thousands of files and applying the same transformation repeatedly, you define a recipe and let OpenRewrite perform the transformation consistently across the codebase.
For large migrations, this is particularly useful for changes that are:
- Repetitive
- Syntactic
- Well-understood
- Applicable across many files
The important distinction is that OpenRewrite automates code transformation. It does not understand every business rule or runtime behavior in an enterprise application.
Our Migration
The application was originally running on:
Java 8
Spring Boot 2.3.3
We moved toward:
Java 25
Spring Boot 3.3.4
One of the major changes introduced by Spring Boot 3 was the migration from the older Java EE namespace to Jakarta EE.
For example:
import javax.persistence.Entity;
became:
import jakarta.persistence.Entity;
When you have thousands of source files, this is exactly the kind of transformation that should not be performed manually.
Configuring OpenRewrite
For our migration, we used the OpenRewrite Maven plugin:
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.41.0</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>5.20.0</version>
</dependency>
</dependencies>
</plugin>
We then executed:
mvn rewrite:run
That's it.
The tool analyzed the codebase and applied the configured recipe.
What Happened?
The results were better than we expected. 2,384 files changed. OpenRewrite modified approximately 2,384 Java files.
The majority of the changes were mechanical framework migration changes. Some of the important changes included:
1. javax → jakarta
A large number of imports were automatically migrated.
For example:
javax.persistence.*
became:
jakarta.persistence.*
This is one of the areas where automated refactoring provides tremendous value.
A developer doesn't need to manually locate every affected file.
2. Spring Batch API Changes
Our application also contained Spring Batch code.
Older APIs such as:
JobBuilderFactory
StepBuilderFactory
needed to be migrated toward the newer builder APIs:
JobBuilder
StepBuilder
OpenRewrite handled a significant portion of these changes automatically. This was particularly useful because Spring Batch code was spread across the application.
3. Other Spring Boot Migration Changes
The Spring Boot migration recipes can also handle many other framework-level changes, including API and configuration changes.
The exact transformations depend on the Spring Boot version and the recipe version being used.
The OpenRewrite Spring Boot migration documentation provides the applicable transformation set and before/after examples.
How Much Time Did It Save?
This was probably the biggest practical benefit.
Our initial estimate for manually performing the large-scale refactoring was approximately 5–7 days. OpenRewrite completed the core source transformation in minutes. We then spent approximately 4 hours reviewing the generated changes.
This is an important distinction. We did not treat the generated code as automatically correct. The workflow was:
OpenRewrite
↓
Automated transformation
↓
Code review
↓
Compilation
↓
Unit/integration testing
↓
Manual fixes
This turned the migration from a large manual refactoring exercise into a much more controlled process.
But OpenRewrite Did Not Migrate Everything
This was the most important lesson from our experience. OpenRewrite was extremely effective for structural and mechanical changes.
However, there were areas where application-specific knowledge was required. The DAO layer was one example. Our application contained a significant amount of legacy SQL code.
SQL Built Using String Concatenation
Some queries were constructed using direct string concatenation.
For example:
String sql = "SELECT ... WHERE customer_id = " + customerId;
These situations required manual intervention. The problem wasn't simply changing Java syntax. We needed to understand the SQL, parameter handling, and application behavior. OpenRewrite could transform Java source code, but it could not safely determine the business intent behind every SQL statement.
Legacy Named Parameters
We also discovered another interesting problem during testing.
Some legacy DAO code used parameters such as:
:1
:2
The code compiled successfully after the migration.
However, during runtime testing, some of these parameters failed to bind correctly. We had to manually replace them with explicit names such as:
:customerId
:employeeId
This was a good example of why successful compilation does not mean a migration is complete.
The problem surfaced only when the application actually executed the affected code.
What About Java 25?
There is another important point when planning a Java 8 → Java 25 migration. Spring Boot migration and Java migration are related, but they are not the same transformation. OpenRewrite provides Java migration recipes as well.
For example, there is a dedicated recipe for migrating to Java 25:
org.openrewrite.java.migrate.UpgradeToJava25
The Java 25 migration guide currently describes this recipe as part of the rewrite-migrate-java recipe module. The important thing is to select the recipes appropriate for the actual migration path.
For example:
Java 8
↓
Java 17
↓
Java 21
↓
Java 25
or combine applicable migration recipes depending on the project's starting point and the changes required.
A Java 25 recipe should not be treated as a replacement for the Spring Boot migration recipe. They address different parts of the modernization.
Useful OpenRewrite Recipes for Java/Spring Modernization
One of the things I like about OpenRewrite is that the migration doesn't have to stop with one recipe. Depending on the application, you can combine recipes for different modernization goals.
Some useful categories include:
Spring Boot
For example:
org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3
This was the recipe we used for our Spring Boot 3.3 migration. OpenRewrite also maintains Spring Boot migration recipes for newer Spring Boot versions.
Java
For Java modernization, OpenRewrite provides recipes such as:
org.openrewrite.java.migrate.UpgradeToJava25
The Java migration recipes can target language/API modernization separately from Spring-specific changes.
Other Framework/API Migrations
The OpenRewrite recipe ecosystem also contains recipes for other common modernization scenarios.
This is where OpenRewrite becomes more interesting than a simple search-and-replace tool. Recipes can encode relationships between APIs and perform structured transformations rather than blindly replacing text.
What OpenRewrite Is Good At
Based on our experience, I would categorize the work this way.
Excellent Candidates for Automation
javax → jakarta
Known API replacements
Deprecated API migrations
Repetitive source changes
Large-scale mechanical refactoring
Areas Requiring Engineering Judgment
Business logic
SQL semantics
Security behavior
Application-specific configuration
Runtime behavior
This distinction is critical. You don't want to ask:
"Can OpenRewrite migrate my application?"
A better question is:
"Which parts of my migration can be safely automated?"
Automation Does Not Remove Testing
One of the biggest mistakes would be to run:
mvn rewrite:run
and assume the migration is finished.
Our experience showed the opposite. The automated changes actually allowed us to spend more time on the areas that mattered. Instead of having developers spend days changing thousands of imports and APIs, we could focus our engineering effort on:
- Reviewing generated changes
- Fixing application-specific issues
- Validating SQL behavior
- Testing Spring Batch behavior
- Validating security configuration
- Running integration tests
- Investigating runtime failures
The tool didn't remove engineering work.
It moved engineering effort from repetitive refactoring to higher-value validation.
Our Takeaway
The most impressive part of OpenRewrite wasn't that it changed 2,384 files.
It was that it allowed us to approach a large migration differently.
Without automation:
Thousands of files
↓
Manual changes
↓
5–7 days
↓
High risk of inconsistency
With OpenRewrite:
Migration recipe
↓
2,384 files transformed
↓
Minutes
↓
Code review
↓
Testing
↓
Manual fixes where required
The lesson I took from the migration is simple:
Automate the mechanical work. Keep human judgment for the work that requires application context.
OpenRewrite doesn't eliminate the complexity of a Java/Spring modernization.
But for a large legacy application, it can dramatically reduce the amount of repetitive work engineers need to perform — and make the overall migration much more controlled and repeatable.
Opinions expressed by DZone contributors are their own.