#1
When you're building a Spring Boot application that needs to store and retrieve files—whether it's user uploads, logs, backups, or documents—you’ll want a reliable and simple object storage system. One of the best choices out there is MinIO, a high-performance, self-hosted object storage solution that’s fully compatible with Amazon S3 APIs.
In this article, you’ll learn how to configure MinIO in your Spring Boot application using the application.properties file. We’ll look at two environments: a local development setup and a production setup where MinIO settings are provided through a Kubernetes ConfigMap.
Let’s get started.

MinIO Configuration: The Basics

To use MinIO in your Spring Boot app, you'll typically need three pieces of information:

  1. MinIO URL – where your MinIO server is running.
  2. Access Key – like a username.
  3. Secret Key – like a password.

These credentials are needed to authenticate your application with MinIO and perform operations like uploading or downloading files.

Production Environment Setup with Kubernetes

When deploying to production (especially on Kubernetes), you don’t want to hard-code sensitive values in your .properties file. Instead, it’s a best practice to inject them using environment variables, ideally from a Kubernetes ConfigMap.

Step 1: Create a ConfigMap for MinIO

Create a ConfigMap named minio-config with the necessary values. Here’s an example:

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

Step 2: Inject ConfigMap Values as Environment Variables

In your Kubernetes Deployment YAML, inject the values into the container environment:

containers:
- name: spring-boot-app
  image: your-app-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

These values will now be available as environment variables inside your Spring Boot app.

application.properties for Production

Now, back in your Spring Boot project, use environment variable placeholders in application.properties like this:

minio.url=${MINIO_URL}
minio.accessKey=${MINIO_ACCESS_KEY}
minio.secretKey=${MINIO_SECRET_KEY}

Spring Boot will automatically resolve these using the environment variables set by Kubernetes.

Optional: Use Spring Profiles for Flexibility

To keep things clean and separate between dev and prod environments, use Spring Boot profiles.
Create:

  • application-dev.properties
  • application-prod.properties

application-dev.properties

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

application-prod.properties

minio.url=${MINIO_URL}
minio.accessKey=${MINIO_ACCESS_KEY}
minio.secretKey=${MINIO_SECRET_KEY}

Then, when you run the app, just specify the profile:

SPRING_PROFILES_ACTIVE=prod

Spring Boot will load the correct config file based on the active profile.


image quote pre code