Quick revision
The short answer
We should fix deprecation warnings in the current version, before upgrading, because deprecated APIs are usually removed in a later release and the replacement already exists now. The Javadoc of a deprecated API usually names its replacement, and compiling with -Xlint:deprecation shows every place we use one. Fixing them one by one while both APIs work turns the upgrade into a small step.
What to remember
In this answer, we saw that a deprecation in Spring warns that the API will be removed in a later release, usually the next major. We fix deprecations on the current version, where the old and new APIs both work, find them with -Xlint:deprecation and -Xlint:removal, follow the Javadoc to the replacement, and check deprecated configuration properties with the IDE and the properties migrator before upgrading.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
We should fix deprecation warnings in the current version, before upgrading, because deprecated APIs are usually removed in a later release and the replacement already exists now. The Javadoc of a deprecated API usually names its replacement, and compiling with -Xlint:deprecation shows every place we use one. Fixing them one by one while both APIs work turns the upgrade into a small step.
Why this question is asked
Deprecation warnings are easy to ignore. The code compiles, the tests pass and the warning scrolls past in the build log. Then the next major release removes the API, and a dozen small, easy fixes become a broken build in the middle of an upgrade. Interviewers ask this question to see whether we understand what a deprecation means in Spring's release policy and how to deal with it as routine work. In this answer, we will recap what deprecation means, see why the current version is the right time to fix it, find every use with the compiler, follow the Javadoc to the replacement, and look at deprecated configuration properties too.
1A Quick Recap of Deprecation
A deprecated API is one that still works but that its authors want us to stop using, usually because a better one exists. In Java it is marked with the @Deprecated annotation, and in the Javadoc with an @deprecated tag that explains why and what to use instead. Since Java 9, the annotation can say since which version it is deprecated and whether it is planned for removal, with forRemoval = true.
Spring follows a clear pattern: an API is deprecated in one release and removed in a later one, usually the next major. Boot 3 removed what Boot 2.x deprecated, and Boot 4 removes what Boot 3.x deprecated. So a deprecation warning is a message from the future: this line will not compile after the upgrade.
2Why Fix It in the Current Version
While we are on the current version, both the old and the new API exist. We can change one usage, run the tests, and release it like any other change. If something behaves differently, we know exactly which change caused it.
After the upgrade, the old API is gone. All the usages fail at once, mixed with other changes from the new release, and we have to fix them under pressure on a migration branch. The fixes themselves are the same; what changes is the risk and how hard it is to find the cause of a problem.
So the rule is simple: fix deprecations while the replacement and the old API live side by side, then upgrade.
| Aspect | Fixed on the current version | Left until after the upgrade |
|---|---|---|
| Old API | still works | removed, compile error |
| Size of change | one usage per commit if we like | all usages at once |
| Testing | normal tests, normal release | mixed with every other upgrade change |
| Finding a cause | the one change in that commit | many candidates on one branch |
3Finding Every Use With -Xlint:deprecation
By default, javac only prints a short note that some files use deprecated APIs, without saying where. Removal warnings, for APIs marked forRemoval, are shown by default, but ordinary deprecations are not. Passing -Xlint:deprecation makes the compiler list each use with file and line.
Notice that the warning includes the exact type and package, which is all we need to look it up. In a large project, counting these warnings per module gives a simple measure of how much preparation is left.
4Following the Javadoc to the Replacement
Spring's Javadoc for a deprecated type or method almost always says what to use instead, and often since which version the replacement exists. For @MockBean it points to @MockitoBean from Spring Framework's test support. The release notes and the migration guide of the version that introduced the deprecation usually explain the reason as well.
Sometimes the replacement is not a one-line swap and needs a small design change, as when Spring Security deprecated WebSecurityConfigurerAdapter in favour of SecurityFilterChain beans. Those are exactly the cases we want to handle calmly on the current version. For common, mechanical cases, OpenRewrite recipes can apply the change across the whole codebase.
5Deprecated Configuration Properties
Deprecations are not only in Java code. Boot also deprecates configuration properties, and the compiler cannot see those. IDEs that read Boot's configuration metadata show deprecated keys in application.yml with a strike-through and the replacement. And the spring-boot-properties-migrator dependency, added temporarily at runtime, reports renamed and removed keys from every property source at startup.
So the full preparation before an upgrade is: compile with deprecation warnings and fix them, check properties with the IDE and the migrator, then move to the new version, where the release notes cover the few remaining changes.
6Follow-up questions
Should we fail the build on deprecation warnings?
Not for all existing ones at once, because that blocks every team. A better rule is to fail on new deprecations introduced in changed code, track the total count, and bring it down over time. Once it reaches zero, failing on any deprecation with -Werror is reasonable for some projects.
What if a deprecated API has no replacement yet?
That happens occasionally. Read the Javadoc and the issue tracker for the reason, suppress the warning locally with @SuppressWarnings and a comment explaining why, and track it so it is revisited before the upgrade.
Do deprecations in third party libraries matter too?
Yes, for the same reason. A library that deprecates something will remove it in its next major, and Boot upgrades often bring library majors with them. The same -Xlint output covers library APIs we call.
7Conclusion
In this answer, we saw that a deprecation in Spring warns that the API will be removed in a later release, usually the next major. We fix deprecations on the current version, where the old and new APIs both work, find them with -Xlint:deprecation and -Xlint:removal, follow the Javadoc to the replacement, and check deprecated configuration properties with the IDE and the properties migrator before upgrading.
Open with
I treat deprecation warnings as a to-do list for the next upgrade. In Spring, an API that is deprecated in one release is usually removed in a later one, typically the next major, so Boot 4 removes what Boot 3 deprecated.
Then, if they want more
The best time to fix them is on the current version, because the replacement already exists and the old API still works, so I can change one usage, run the tests and release it normally. If I wait, all of them break at once in the middle of the upgrade, mixed with every other change.
To find them, I compile with -Xlint:deprecation and -Xlint:removal, because by default javac only prints a short summary for ordinary deprecations. Each warning names the type and package, and Spring's Javadoc almost always says what to use instead. For example, @MockBean is deprecated since Boot 3.4 and the Javadoc points to @MockitoBean.
For mechanical cases across many files I use OpenRewrite recipes. I also check deprecated configuration properties, which the compiler cannot see, with the IDE and the properties migrator. In a large codebase I track the warning count and block only new ones, so teams are not stopped by old debt.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 9, Spring Boot 3.4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "How should you deal with deprecation warnings in Spring Boot before an upgrade?": https://scrivio-interview-library.netlify.app/spring-boot/boot-migrations/4719ca441d/