📄
Configuration

XML Configuration (Legacy)

Purana Approach
💡 XML configuration ek HANDWRITTEN LETTER hai — kaam ho jaata hai, lekin verbose hai, typos ka risk hai, aur processing (parsing) slow hai. Java-config ek TYPED EMAIL hai — fast, validated, aur autocomplete ke saath.

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 configuration ek HANDWRITTEN LETTER hai — kaam ho jaata hai, lekin verbose hai, typos ka risk hai, aur processing (parsing) slow hai. Java-config ek TYPED EMAIL hai — fast, validated, aur autocomplete ke saath.
1 / 2
⚡ झट से Recap
  • 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
इस page में (2 subtopics)

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.

💡Tip: Naye projects mein XML config LIKHNA hi NAHI chahiye — ye purely LEGACY maintenance ke liye samajhna zaroori hai, naya code likhते waqt hamesha annotations/Java-config use karo.