Skip to main content
The User Management API uses Spring Boot’s configuration system with YAML files and environment variables for flexible configuration across different environments.

Configuration Files

The application uses a multi-profile configuration approach:

application.yaml

Main configuration file with production defaults

application-local.yaml

Local development overrides with verbose logging

File Locations

  • src/main/resources/application.yaml - Main configuration
  • src/main/resources/application-local.yaml - Local development profile
  • src/main/resources/db/migration/ - Flyway database migrations

Core Configuration

Application Properties

application.yaml
spring:
  application:
    name: user-management-api

  profiles:
    active: ${ENVIRONMENT:local}
The active profile defaults to local and can be overridden with the ENVIRONMENT environment variable.

Database Configuration

DataSource Settings

The application uses PostgreSQL as its primary database:
application.yaml
spring:
  datasource:
    url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/user_db}
    username: ${SPRING_DATASOURCE_USERNAME:postgres}
    password: ${SPRING_DATASOURCE_PASSWORD:password}
    driver-class-name: org.postgresql.Driver
Never commit database credentials to version control. Use environment variables for production deployments.

JPA and Hibernate

Production settings:
application.yaml
spring:
  jpa:
    hibernate:
      ddl-auto: none
    show-sql: false
    properties:
      hibernate:
        format_sql: false
        dialect: org.hibernate.dialect.PostgreSQLDialect
Local development settings:
application-local.yaml
spring:
  jpa:
    hibernate:
      ddl-auto: validate
    show-sql: true
    properties:
      hibernate:
        format_sql: true
        dialect: org.hibernate.dialect.PostgreSQLDialect
    defer-datasource-initialization: false
The local profile enables SQL logging and formatting for easier debugging.

Flyway Migrations

Flyway handles database schema versioning:
application.yaml
spring:
  flyway:
    enabled: true
    url: ${spring.datasource.url}
    user: ${spring.datasource.username}
    password: ${spring.datasource.password}
    locations: classpath:db/migration
    baseline-on-migrate: true
    validate-on-migrate: true
Migration scripts are located in src/main/resources/db/migration/ and follow the naming pattern V{version}__{description}.sql.

Environment Variables

The following environment variables can be used to override configuration:

Required Variables

VariableDefaultDescription
ENVIRONMENTlocalActive Spring profile (local, dev, prod)
SPRING_DATASOURCE_URLjdbc:postgresql://localhost:5432/user_dbDatabase JDBC URL
SPRING_DATASOURCE_USERNAMEpostgresDatabase username
SPRING_DATASOURCE_PASSWORDpasswordDatabase password

Example Usage

export ENVIRONMENT=prod
export SPRING_DATASOURCE_URL=jdbc:postgresql://prod-db:5432/user_db
export SPRING_DATASOURCE_USERNAME=prod_user
export SPRING_DATASOURCE_PASSWORD=secure_password

./gradlew bootRun

Actuator Configuration

Spring Boot Actuator provides health checks and monitoring endpoints:
application.yaml
management:
  endpoints:
    web:
      exposure:
        include: health,info
  endpoint:
    health:
      show-details: always

Available Endpoints

EndpointURLDescription
Health Check/actuator/healthApplication health status
Info/actuator/infoApplication information
The health endpoint is used by Cloud Run and other platforms for readiness and liveness probes.

OpenAPI Configuration

OpenAPI documentation is configured in the local profile:
application-local.yaml
springdoc:
  api-docs:
    path: /api-docs
    enabled: true
  swagger-ui:
    path: /swagger-ui.html
    enabled: true
    operationsSorter: method
    tagsSorter: alpha
    displayRequestDuration: true
    defaultModelsExpandDepth: 1
    defaultModelExpandDepth: 1
    tryItOutEnabled: true
    filter: true
  show-actuator: false
  packages-to-scan: com.fbaron.user
  paths-to-match: /api/**

Accessing Documentation

OpenAPI documentation is enabled in the local profile for development. Consider security implications before enabling in production.

Profile-Specific Configuration

Local Profile

Activated automatically by default, provides:
  • Verbose SQL logging (show-sql: true)
  • Formatted SQL output (format_sql: true)
  • Database schema validation (ddl-auto: validate)
  • Enabled Swagger UI

Production Profile

Optimized for production:
  • Minimal logging (show-sql: false)
  • No schema generation (ddl-auto: none)
  • Environment-specific database credentials
  • Actuator endpoints for monitoring

Configuration Best Practices

1

Use Environment Variables for Secrets

Never hardcode credentials. Use environment variables for sensitive data:
spring:
  datasource:
    password: ${SPRING_DATASOURCE_PASSWORD}
2

Separate Profiles by Environment

Create profile-specific files for different environments:
  • application-local.yaml - Local development
  • application-dev.yaml - Development server
  • application-prod.yaml - Production
3

Override with External Configuration

Place an application.yaml outside the JAR for runtime overrides:
java -jar app.jar --spring.config.location=/config/application.yaml
4

Use Configuration Validation

Validate configuration on startup using Spring’s @ConfigurationProperties with validation annotations.

Cloud Deployment Configuration

For Google Cloud Run deployment (as configured in cloudbuild.yaml), secrets are managed via Secret Manager:
cloudbuild.yaml
--set-secrets
SPRING_DATASOURCE_URL=CONTABO_DB_URL:latest,
SPRING_DATASOURCE_USERNAME=CONTABO_DB_USER:latest,
SPRING_DATASOURCE_PASSWORD=CONTABO_DB_PASSWORD:latest
When deploying to cloud platforms, use their native secret management services instead of environment variables.

Troubleshooting

Ensure the profile is active:
./gradlew bootRun --args='--spring.profiles.active=local'
Check the startup logs for:
The following profiles are active: local
Verify your database configuration:
  1. Check PostgreSQL is running: pg_isready
  2. Verify credentials in application.yaml
  3. Test connection: psql -h localhost -U postgres -d user_db
If migrations fail:
  1. Check migration scripts in src/main/resources/db/migration/
  2. Verify baseline: spring.flyway.baseline-on-migrate=true
  3. Check Flyway history: SELECT * FROM flyway_schema_history;
Check the property precedence:
  1. Command line arguments (highest priority)
  2. Environment variables
  3. Profile-specific YAML files
  4. Default application.yaml (lowest priority)

Next Steps

Docker Setup

Learn how to run the application in Docker

Testing

Understand the testing configuration

API Reference

Explore the API endpoints

Architecture

Learn about the system architecture

Build docs developers (and LLMs) love