#1
When your Spring Boot application needs to handle file uploads, image storage, or even document management, MinIO is a great tool to use. It’s lightweight, S3-compatible, and easy to set up locally or in the cloud.
This guide walks you through how to configure MinIO in a Spring Boot application using application.yml files. We’ll cover settings for both development and production environments. For production, we’ll show how to pull values from a Kubernetes ConfigMap.
Let’s keep it simple and to the point.

What You Need to Configure

To connect Spring Boot with MinIO, you need to define the following:

  • url: MinIO server endpoint
  • accessKey: your MinIO username or access ID
  • secretKey: your MinIO password or secret key

These values can live in your configuration files or be injected as environment variables—depending on your environment (dev vs prod).

Configure in application.yml

Here’s how to set up MinIO settings in your application-dev.yml:

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

Now your app knows how to connect to MinIO during development!

Production Configuration (with Kubernetes ConfigMap)

In production, you should never hardcode secrets or environment-specific values. Instead, use a Kubernetes ConfigMap to safely manage configuration.

Step 1: Create the ConfigMap

Let’s create a ConfigMap called minio-config. Here’s the YAML:

apiVersion:v1
kind:ConfigMap
metadata:
  name:minio-config
  namespace:your-namespace
data:
  urlMinIO:http://minio-service:9000
  accesskey:your-access-key
  secretkey:your-secret-key

This ConfigMap holds the MinIO settings you’ll inject into your Spring Boot app.

Step 2: Use ConfigMap in Deployment

In your deployment YAML, pass the values as environment variables to your app container:

containers:
  - name: your-app
    image: your-image
    env:
     - name: MINIO_URL
       valueFrom:
        configMapKeyRef:
         name: minio-config
         key: urlMinIO
     - name: MINIO_ACCESS_KEY
       valueFrom:
        configMapKeyRef:
         name: minio-config
         key: accesskey
     - name: MINIO_SECRET_KEY
       valueFrom:
        configMapKeyRef:
         name: minio-config
         key: secretkey

This will make the MinIO details available to Spring Boot as environment variables.

Step 3: Read Values in Spring Boot

Update your Spring configuration files to use the environment variables.

application-prod.yml for production

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

Spring Boot will automatically replace the placeholders with the values from the environment.

Using Spring Profiles (dev & prod)

To manage different settings for development and production, use Spring profiles.
Create separate config files:

  • application-dev.yml → used during local development
  • application-prod.yml → used in production (e.g., in Kubernetes)

Then, activate the correct profile by setting the SPRING_PROFILES_ACTIVE environment variable.
For local:

SPRING_PROFILES_ACTIVE=dev

For Kubernetes:

env:
  name: SPRING_PROFILES_ACTIVE
  value: prod

Each profile loads its own settings, keeping dev and prod cleanly separated.


image quote pre code