XML Configuration (Legacy)
XML-based configuration Spring ka ORIGINAL approach tha (2003) — beans <bean> tags mein define hoti thi, dependencies <constructor-arg>/<property> tags se wire hoti thi. Verbose thi, aur RUNTIME tak errors pakdi nahi jaati thi (typo in class name = runtime exception, compile-time nahi).
Aaj XML config LEGACY hai — naye projects ise use nahi karte. Lekin BADI, PURANI enterprise applications mein aaj bhi milता hai, isliye samajhna zaroori hai — kaam par aisi codebase mil sakti hai jo abhi tak migrate nahi hui.
<!-- Purana XML style -->
<beans xmlns="http://www.springframework.org/schema/beans">
<bean id="userRepository" class="com.example.UserRepository" />
<bean id="userService" class="com.example.UserService">
<constructor-arg ref="userRepository" />
</bean>
</beans>
<!-- Java mein load karna: -->
<!-- ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); -->- XML = Spring ka original (2003) configuration style
- Naye projects mein use NAHI hota — legacy maintenance ke liye important
- Java-config se verbose, aur runtime-only error detection
XML configuration Spring ka SABSE PURANA style hai (2003-era) — aaj ke naye projects mein RARELY use hota hai, lekin bade, LEGACY enterprise codebases mein aaj bhi milता hai. Java-based/annotation config XML se BEHTAR hai — type-safe hai (compile-time errors), refactoring-friendly hai (IDE support behtar).
<!-- applicationContext.xml -->
<beans>
<bean id="emailService" class="com.example.EmailService" />
<bean id="userService" class="com.example.UserService">
<constructor-arg ref="emailService" />
</bean>
</beans>Purane XML-based projects ko GRADUALLY Java-config mein migrate kiya ja sakta hai — @ImportResource annotation se, XML aur Java config EK SAATH bhi chal sakte hain transition period ke dauraan.