#1
When building a Spring Boot application, connecting to external services like MinIO for file storage and PostgreSQL for your database is a common and essential step. One of the cleanest ways to manage these configurations is by using the application.yml file.
But if your app needs to run in different environments—like development (dev) and production (prod), you don’t want to hardcode these settings. Instead, you can separate the configuration using Spring profiles.
In this article, we’ll walk through how to configure both MinIO and PostgreSQL using application.yml, with separate settings for dev and prod environments.
Let’s get started!

What You'll Learn

  • How to structure application.yml for multiple environments
  • How to set up MinIO and PostgreSQL configurations
  • How to switch between dev and prod profiles
  • How to load sensitive data from environment variables (recommended for prod)

Basic Structure of application.yml

Spring Boot allows you to use a single application.yml file with multiple profile-specific sections. You can define a base configuration and then override or add values under specific profiles like this:
spring:
  profiles:
    active: dev
Then, define environment-specific blocks using --- and spring.profiles:
# Default settings (optional)
spring:
  application:
    name: myapp

---
spring:
  profiles: dev
# dev config here

---
spring:
  profiles: prod
# prod config here
Now, let’s apply this to MinIO and PostgreSQL.

Configure MinIO in application.yml

Configure PostgreSQL in application.yml

Full Example of application.yml

Here’s what a complete setup could look like using both dev and prod profiles:

Development (Local or Docker)

spring:
  profiles: dev

minio:
  url: http://localhost:9000
  accessKey: minioadmin
  secretKey: minioadmin123

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/devdb
    username: postgres
    password: postgres
    driver-class-name: org.postgresql.Driver
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    database-platform: org.hibernate.dialect.PostgreSQLDialect

Production (Secure and Flexible)

spring:
  profiles: prod

minio:
  url: ${MINIO_URL}
  accessKey: ${MINIO_ACCESS_KEY}
  secretKey: ${MINIO_SECRET_KEY}

spring:
  datasource:
    url: ${DB_URL}
    username: ${DB_USERNAME}
    password: ${DB_PASSWORD}
    driver-class-name: org.postgresql.Driver
  jpa:
    hibernate:
      ddl-auto: validate
    show-sql: false
    database-platform: org.hibernate.dialect.PostgreSQLDialect

How to Switch Between Dev and Prod

Spring Boot uses the spring.profiles.active property to determine which block of configuration to load.

Option 1: Change it in application.yml

spring:
  profiles:
    active: prod

Option 2: Pass it as a startup argument (recommended for production)

java -jar yourapp.jar --spring.profiles.active=prod

Option 3: Use environment variable

export SPRING_PROFILES_ACTIVE=prod

Best Practices

  • Use application.yml for clean and readable configuration
  • Separate dev and prod settings using spring.profiles
  • Avoid hardcoding secrets—use environment variables in production
  • Set dev profile as default during development
  • Use ddl-auto: update in dev, and validate or none in prod

image quote pre code