Quick revision
The short answer
XML configuration still works in current Spring, so nothing forces a migration; the real costs are readability and the shrinking number of engineers who know XML well. I would convert services when they are being actively changed and have tests to prove the conversion, start with the services that block upgrades or that new engineers struggle to change, and take extra care where AOT or native images are planned, because XML and dynamic registration need checking there for each version. A few tested example conversions and a short guide make each migration routine.
What to remember
In this answer, we saw that XML still works in Spring, so there is no forced migration; the costs are readability and skills. We convert services when they are actively changed and have tests, because conversion without tests is risky, and we prioritise services whose XML blocks upgrades or that new engineers struggle to change. Services targeting AOT or native images need more care with XML and dynamic registration, so we check the support in our version. A few tested example conversions and a guide keep each migration small and routine.
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.
XML configuration still works in current Spring, so nothing forces a migration; the real costs are readability and the shrinking number of engineers who know XML well. I would convert services when they are being actively changed and have tests to prove the conversion, start with the services that block upgrades or that new engineers struggle to change, and take extra care where AOT or native images are planned, because XML and dynamic registration need checking there for each version. A few tested example conversions and a short guide make each migration routine.
Why this question is asked
Many companies have services from the Spring 2 and 3 era, with thousands of lines of applicationContext.xml that still run in production every day. A senior engineer is expected to have a plan that neither ignores them forever nor launches a risky big-bang rewrite. Interviewers ask this to see how we weigh cost, risk and value across a portfolio of systems. In this answer, we will recap how the configuration styles relate, look at what XML actually costs today, decide which services to convert first, walk through a safe conversion with an example, look at the AOT question, and finish with the support material that makes the plan sustainable.
1A Quick Recap: Three Generations of Configuration
Early Spring described beans in XML files: a <bean> element with a class, constructor arguments and properties. Spring 2.5 added annotations such as @Component and @Autowired with component scanning, and Spring 3 added Java configuration with @Configuration classes and @Bean methods. Spring Boot then built auto-configuration on top of Java configuration. Most recently, Spring AOT processes configuration at build time and generates Java code that registers beans, which native images require.
The important fact is that all of these produce the same thing inside the container: bean definitions. An XML <bean> and a @Bean method end up as equivalent recipes. So XML is not deprecated in the sense of being removed; it is still supported and can be mixed with Java configuration through @ImportResource.
2What XML Actually Costs Today
Because the old services work, the case for change must rest on real costs. The first is readability: XML is verbose, refers to classes and properties by string, and is not checked by the compiler, so a renamed class or a typo in a property name fails only at startup. Refactoring tools in IDEs handle Java far better. The second is skills: engineers who joined in the last ten years have mostly never written Spring XML, so changes take longer and carry more risk, and reviews are weaker.
The third cost appears at upgrade time. Old XML often uses namespaces and features of libraries that later versions removed or changed, for example older Spring Security or integration namespaces, and the error messages for broken XML are often less helpful. None of these costs is urgent for a service nobody touches, which is the key insight for the plan.
3Which Services to Convert First
I would not convert everything on a schedule. Conversion without good tests is risky: a missing property or a different bean order can change behaviour in ways that only show in production. So the plan ties conversion to change. A service that a team is actively developing, with decent test coverage, is converted as part of that work, a module at a time. A stable service nobody touches stays in XML until there is a reason.
Within the active group, priority goes to two kinds of service. First, those whose XML blocks an upgrade, for example a Spring Framework or Spring Boot major version, the Jakarta namespace change, or a security patch that needs a newer library. Second, those that new engineers struggle to change, where onboarding time or incident reports show the configuration is a real obstacle. Those are where conversion pays back fastest.
- Is the XML blocking an upgrade or fix?YesConvert now, with tests firstNoGo on
- Is the service actively changed?YesGo onNoLeave it in XML, revisit yearly
- Are there enough tests to prove behaviour?YesConvert module by moduleNoAdd tests first
- Record the conversion in the guideexamples help the next team
4 steps in order. Play them, or step through them one at a time.
4How a Conversion Goes, Step by Step
The safest path is gradual. Spring lets a Java configuration class import existing XML with @ImportResource, so the service can start with Java configuration as the entry point and move beans out of XML a file or a section at a time. Each step is small enough to review and to test.
Notice that the bean names stay the same, orderRepository and orderService, because other XML or code may refer to them by name. Before and after each step, a context test should assert the same set of bean names and types, and the service's integration tests should pass unchanged. Comparing the Actuator beans endpoint output before and after is a cheap extra check.
5The AOT and Native Image Question
Services that will move to Spring AOT or GraalVM native images need extra care. AOT works from the final bean definitions at build time, and support for XML-defined beans, custom namespaces and dynamic registration has been more limited than for Java configuration, and has changed across versions. So for those services, conversion moves up the list, and we check the AOT documentation of the exact Spring version we target rather than assuming.
For services that will stay on a normal JVM, XML has no AOT cost, which is one more reason not to convert stable services just for tidiness.
| Service group | Plan | Reason |
|---|---|---|
| Blocks an upgrade | convert now, tests first | the XML has a direct cost |
| Actively changed, good tests | convert during normal work | low risk, high value |
| Actively changed, few tests | add tests, then convert | conversion without tests is risky |
| Targets AOT or native | convert early, check version support | XML support is more limited |
| Stable, rarely touched | leave in XML, review yearly | cost is low, risk is not |
6Making It Sustainable: Examples and a Guide
The plan only works if each team does not have to learn the conversion from scratch. So the platform team keeps a small set of tested example conversions, for typical XML patterns such as data sources, transaction managers, property placeholders, AOP configuration and common namespaces, each as a before-and-after pair with a test that proves the two produce the same beans. A short guide explains the gradual @ImportResource approach, the naming rule and the checks to run.
Finally, track progress lightly: a list of services with XML, their status and the reason for that status. Over a few years the XML shrinks to the services that truly do not change, and those can be retired with the service itself rather than converted.
7Follow-up questions
Would you ever do a big-bang conversion of a whole service?
Only for a small service with excellent tests, where the conversion fits in one reviewable change. For large configurations, a gradual approach with @ImportResource is safer, because each step can be tested and rolled back separately, and the service keeps shipping features throughout.
Should the XML go straight to component scanning?
Not necessarily. Converting each <bean> into an explicit @Bean method is the most faithful translation and keeps names and configuration visible. Moving to @Component and scanning is a separate, later refactoring, and for infrastructure beans explicit @Bean methods are often the better end state anyway.
How do you convince management to fund this?
By tying it to costs they already see: an upgrade blocked by the XML, security patches that take longer, onboarding time for new engineers, or incidents caused by configuration errors. Converting during normal feature work keeps the extra cost small, and the examples and guide reduce it further.
8Conclusion
In this answer, we saw that XML still works in Spring, so there is no forced migration; the costs are readability and skills. We convert services when they are actively changed and have tests, because conversion without tests is risky, and we prioritise services whose XML blocks upgrades or that new engineers struggle to change. Services targeting AOT or native images need more care with XML and dynamic registration, so we check the support in our version. A few tested example conversions and a guide keep each migration small and routine.
Open with
My starting point is that XML still works in current Spring, it produces the same bean definitions as Java config, so there is no forced migration and I would not run a big rewrite.
Then, if they want more
The real costs are readability, no compiler checks and poor refactoring support, and skills, because most engineers who joined in the last decade have never written Spring XML. Those costs only matter when someone changes the service.
So I tie conversion to change: when a team is actively working on a service and it has decent tests, they convert as part of that work, gradually, by adding a Java configuration class that imports the remaining XML with @ImportResource and moving beans out a section at a time, keeping the bean names identical and checking the bean list before and after.
If tests are thin, they add tests first. I would prioritise two groups: services whose XML blocks an upgrade, like a Spring major version or a security fix, and services new engineers struggle to change.
Services that plan to use Spring AOT or native images also move up, because XML and dynamic registration have more limited support there, and I would check the exact version. Stable services nobody touches can stay in XML.
To keep it cheap, the platform team maintains tested before-and-after examples for common patterns and a short guide, so each migration is routine.
About this answer
- Last updated
- 12 November 2026
- 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 Framework reference, Core technologies
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 "Spring configuration moved from XML to annotations and Java configuration, and now to...": https://scrivio-interview-library.netlify.app/spring-boot/ioc-container/5ec796d8bc/