İçeriğe geç
yaml

Spring Boot application.yml Prod/Dev Profil

Spring Boot multi-profile yapılandırması. Development ve production ortamları için ayrı ayarlar.

By Tolgahan · · 315 görüntülenme
yaml
# application.yml - Ortak ayarlar
spring:
  application:
    name: my-service
  jackson:
    serialization:
      write-dates-as-timestamps: false
    default-property-inclusion: non_null

server:
  port: 8080
  shutdown: graceful

management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics
  endpoint:
    health:
      show-details: when-authorized

---
# application-dev.yml - Development
spring:
  config:
    activate:
      on-profile: dev
  datasource:
    url: jdbc:mysql://localhost:3306/myapp_dev
    username: root
    password: secret
  jpa:
    show-sql: true
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        format_sql: true
  data:
    redis:
      host: localhost
      port: 6379

logging:
  level:
    com.example: DEBUG
    org.hibernate.SQL: DEBUG

---
# application-prod.yml - Production
spring:
  config:
    activate:
      on-profile: prod
  datasource:
    url: ${DATABASE_URL}
    username: ${DATABASE_USERNAME}
    password: ${DATABASE_PASSWORD}
    hikari:
      maximum-pool-size: 20
      minimum-idle: 5
      connection-timeout: 30000
  jpa:
    show-sql: false
    hibernate:
      ddl-auto: validate
    properties:
      hibernate:
        generate_statistics: false
  data:
    redis:
      host: ${REDIS_HOST}
      port: ${REDIS_PORT:6379}
      password: ${REDIS_PASSWORD}

logging:
  level:
    root: WARN
    com.example: INFO
Bu snippet'i göm
<iframe src="https://tolgahan.dev/snippets/spring-boot-application-yml-prod-dev-profil/embed" width="100%" height="400" frameborder="0"></iframe>
Paylaş: