Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Interview question

What is the difference between application.properties and application.yml? application.properties और application.yml में क्या अंतर है?

Answer

Both files configure a Spring Boot application externally, but application.properties uses flat key=value pairs, while application.yml uses YAML's indentation-based hierarchy, which reads more cleanly for nested and list-based configuration.

YAML also supports multiple profile documents in a single file separated by ---, whereas properties files typically need separate profile-specific files. Functionally they are equivalent and mapped to the same underlying Environment abstraction, so the choice is largely a readability and team-convention preference.

# application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/db
    username: root

# application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=root

दोनों फाइलें स्प्रिंग बूट एप्लिकेशन को बाहरी रूप से कॉन्फिगर करती हैं, लेकिन application.properties फ्लैट key=value जोड़ों का उपयोग करता है, जबकि application.yml इंडेंटेशन-आधारित पदानुक्रम का उपयोग करता है, जो नेस्टेड कॉन्फिगरेशन के लिए अधिक स्पष्ट होता है।

YAML एक ही फाइल में --- से अलग किए गए कई प्रोफाइल डॉक्यूमेंट्स को भी सपोर्ट करता है। दोनों फंक्शनली समान हैं और एक ही Environment एब्सट्रैक्शन से मैप होते हैं, इसलिए चुनाव मुख्य रूप से पठनीयता और टीम कन्वेंशन पर निर्भर करता है।

# application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/db
    username: root

# application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/db
spring.datasource.username=root

Was this answer clear?