The 4 Eras of Spring: From XML to Spring Boot
15/04/25
5 mins
The 4 Eras of Spring: From XML to Spring Boot
If you’ve ever dipped your toes into the world of Spring Framework, you’ve probably noticed there are many ways to configure a Spring application. Over the years, Spring has evolved from XML-heavy setups to sleek, annotation-driven codebases with Spring Boot doing most of the heavy lifting.
Let’s walk through the four major ways to work with the Spring core — starting from the good old XML days all the way to the modern Spring Boot era.
️ 1. XML Configuration — The OG Way
Back in the early 2000s, Spring was all about XML. You had to define everything — your beans, their dependencies, scopes — inside bulky XML files.
Example:
<bean id="car" class="com.example.Car"> <property name="engine" ref="engine"/> </bean> <bean id="engine" class="com.example.Engine"/>
Pros:
- Clean separation between configuration and code
- Still found in a lot of older (aka “legacy”) systems
Cons:
- Verbose and tedious
- Easy to mess up and hard to maintain
- Not exactly loved by developers
️ 2. XML + Annotations — The Transitional Phase
As Java annotations became more popular, Spring adapted by letting developers annotate their classes with
Java:
@Component public class Engine {} @Component public class Car { @Autowired Engine engine; }
XML:
<context:component-scan base-package="com.example"/>
Pros:
- Less XML clutter
- Brings DI closer to the code
Cons:
- Still stuck with XML for context setup
- Mixing two styles can feel messy
️ 3. Java Config + Annotations — No More XML
Eventually, Spring said: “What if we ditched XML entirely?” Enter Java-based configuration. Using
Java Config Example:
@Configuration public class AppConfig { @Bean public Engine engine() { return new Engine(); } @Bean public Car car() { return new Car(engine()); } }
Or with Annotations Only:
@Component public class Engine {} @Component public class Car { @Autowired Engine engine; }
Bootstrapping it:
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
Pros:
- Type-safe and IDE-friendly
- Fully ditch XML
- Cleaner and more maintainable
️ 4. Spring Boot — Modern Spring Magic
And finally, we arrive at Spring Boot — where most of the magic is done for you. Built on top of Spring’s core features, Spring Boot takes convention over configuration to the next level. No more boilerplate setup, just annotate and go.
Example:
@SpringBootApplication public class MainApp { public static void main(String[] args) { SpringApplication.run(MainApp.class, args); } } @Component public class Engine {} @Component public class Car { @Autowired Engine engine; }
Pros:
- Minimal configuration
- Built-in web server (like Tomcat)
- Auto-configuration and starters
- Great for production-ready apps
Spring Boot is now the de-facto standard for building Spring applications, and for good reason — it just works.
Quick Recap
Approach | XML | Java Config | Annotations | Boot Features |
---|---|---|---|---|
XML Configuration | ✅ | ❌ | ❌ | ❌ |
XML + Annotations | ✅ | ❌ | ✅ | ❌ |
Java Config + Annotations | ❌ | ✅ | ✅ | ❌ |
Spring Boot + Annotations | ❌ | ✅ | ✅ | ✅ |
Final Thoughts
Spring has come a long way, and if you're starting a new project today, Spring Boot is hands-down the way to go. That said, understanding the older styles is super helpful — especially if you’re working on legacy code or preparing for interviews where they might still pop up.