0Pricing
Spring Boot 4 Microservices & REST APIs · Ders

application.properties ve YAML

Uygulamaları properties ve YAML dosyalarıyla yapılandırın.

application.properties ve YAML, CoddyKit'te ücretsiz bir Spring Boot 4 Microservices & REST APIs dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Spring Boot 4 Microservices & REST APIs öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Where Configuration Lives

Spring Boot reads externalized configuration from application.properties or application.yml, placed under src/main/resources. This keeps tunable values out of your compiled code.

At startup Boot loads these files into the Environment, making every key available for injection, conditional beans, and auto-configuration.

  • One file for the whole app, or split per profile
  • Values can be overridden later by env vars or CLI args

The .properties Format

The classic format is a flat list of key=value lines. Nested concepts are expressed with dotted keys.

It is simple and diff-friendly, but verbose when you have deep structures because each key repeats the full path.

server.port=8080
server.servlet.context-path=/api
spring.datasource.url=jdbc:postgresql://localhost:5432/app
spring.datasource.username=app_user
spring.jpa.hibernate.ddl-auto=validate

The YAML Format

application.yml expresses the same data as a hierarchy, so shared prefixes are written once. It is easier to read for deeply nested config like spring.jpa.properties.hibernate.*.

Indentation is significant: use spaces, never tabs, and keep two spaces per level.

server:
  port: 8080
  servlet:
    context-path: /api
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/app
    username: app_user
  jpa:
    hibernate:
      ddl-auto: validate

Lists and Maps in YAML

YAML shines for collections. A sequence uses - items; a map is just nested keys. Spring binds these directly to List and Map properties.

app:
  cors:
    allowed-origins:
      - https://app.example.com
      - https://admin.example.com
  feature-flags:
    beta-search: true
    dark-mode: false

Referencing Other Properties

You can interpolate one property into another with ${...}. This avoids repeating literals and lets a single base value drive several derived keys.

app:
  name: orders-service
  base-url: https://api.example.com
  health-url: ${app.base-url}/actuator/health
logging:
  file:
    name: /var/log/${app.name}.log

Default Values with Placeholders

Inside a placeholder you can supply a fallback after a colon: ${KEY:default}. Spring uses the default when the referenced property or environment variable is absent.

app:
  timeout-ms: ${REQUEST_TIMEOUT:5000}
  region: ${AWS_REGION:eu-central-1}

Injecting Single Values with @Value

For one-off properties, inject directly with @Value. SpEL placeholders resolve against the Environment at bean creation time.

Use @Value for a handful of keys; prefer @ConfigurationProperties when a feature has many related settings.

@Service
public class OrderService {
    @Value("${app.timeout-ms:5000}")
    private long timeoutMs;

    @Value("${app.name}")
    private String appName;
}

Properties vs YAML: Trade-offs

Functionally they are interchangeable; the choice is about ergonomics.

  • .properties — trivial parsing, great for small/flat config, no indentation traps
  • .yml — concise for nested trees, native lists/maps, but indentation-sensitive

If both files exist, .properties takes precedence over .yml for the same key, which can surprise teams. Pick one convention.

Multiple Documents in One YAML

A single YAML file can hold several documents separated by ---. Combined with spring.config.activate.on-profile, this lets you keep common and profile-specific values together.

spring:
  application:
    name: orders
---
spring:
  config:
    activate:
      on-profile: dev
  datasource:
    url: jdbc:h2:mem:devdb

Type Conversion and Durations

Spring converts string values into rich types. Duration accepts suffixes like 30s or 5m, and DataSize accepts 10MB. Enums and List are also converted automatically.

app:
  cache-ttl: 30m
  max-upload: 10MB
  log-level: WARN

Where Not to Put Secrets

Checked-in application.yml is the wrong home for passwords and API keys. Keep secrets in environment variables, a vault, or a secrets manager, and reference them via placeholders.

  • Commit non-sensitive defaults only
  • Inject secrets at deploy time

Quick Check

Test your understanding of property precedence.

Recap

You learned how Spring Boot externalizes configuration.

  • application.properties and application.yml both feed the Environment
  • YAML is concise for nested trees and native lists/maps
  • Use ${...} for references and ${KEY:default} for fallbacks
  • Spring converts to types like Duration and DataSize
  • Keep secrets out of committed files

Sıkça Sorulan Sorular

“application.properties ve YAML” dersi ücretsiz mi?

Evet — “application.properties ve YAML” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Spring Boot 4 Microservices & REST APIs kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.

“application.properties ve YAML” dersinde ne öğreneceğim?

Uygulamaları properties ve YAML dosyalarıyla yapılandırın. Spring Boot 4 Microservices & REST APIs ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Spring Boot 4 Microservices & REST APIs öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Spring Boot 4 Microservices & REST APIs, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“application.properties ve YAML” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Spring Boot 4 Microservices & REST APIs dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Spring Boot 4 Microservices & REST APIs dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. application.properties ve YAML
  2. Ortamlar için Profiller
  3. @ConfigurationProperties ile Tür Güvenli Yapılandırma
  4. Harici ve Geçersiz Kılan Yapılandırma
← Spring Boot 4 Microservices & REST APIs Sayfasına Dön