Step 1: Configure Development and Production Profiles in Spring Boot

AWS Lightsail Deployment Course

2026-04-08

Configure Development and Production Profiles in Spring Boot

Preparing your Spring Boot application for seamless deployment to AWS Lightsail

Why Spring Boot Profiles Matter

Development Environment

  • Local database connections
  • Debug logging enabled
  • Development-friendly settings

Production Environment

  • Cloud database connections
  • Optimized performance settings
  • Security-focused configuration

Base Configuration Setup

Create application.properties with common settings:

# Application name and basic settings
spring.application.name=my-spring-app
server.servlet.context-path=/

# Default active profile
spring.profiles.active=dev

# JPA/Hibernate common settings
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false

Development Profile Configuration

Create application-dev.properties:

# Local MySQL database configuration
spring.datasource.url=jdbc:mysql://localhost:3306/myapp_dev
spring.datasource.username=dev_user
spring.datasource.password=dev_password

# Development-specific settings
spring.jpa.show-sql=true
logging.level.org.springframework.web=DEBUG
server.port=8080

Production Profile Configuration

Create application-prod.properties:

# Production database with environment variables
spring.datasource.url=${DB_URL:jdbc:mysql://localhost:3306/myapp_prod}
spring.datasource.username=${DB_USERNAME:prod_user}
spring.datasource.password=${DB_PASSWORD:secure_password}

# Production optimizations
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=validate
server.compression.enabled=true

Environment Variables in Production

Syntax: ${VARIABLE_NAME:default_value}

Benefits:

  • Secure credential management
  • Environment-specific overrides
  • No hardcoded production secrets
  • Easy configuration changes
spring.datasource.url=
  ${DB_URL:default}

spring.datasource.username=
  ${DB_USERNAME:user}

spring.datasource.password=
  ${DB_PASSWORD:pass}

Build Configuration Updates

Maven Dependencies

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Testing Your Profiles

Development Profile

# Run with development profile (default)
mvn spring-boot:run

# Or explicitly specify
mvn spring-boot:run -Dspring-boot.run.profiles=dev

Production Profile Testing

# Set environment variables
export DB_URL="jdbc:mysql://localhost:3306/myapp_test"
export DB_USERNAME="test_user"

# Run with production profile
mvn spring-boot:run -Dspring-boot.run.profiles=prod

Building for Production

Create deployment-ready JAR:

# Clean and build the project
mvn clean package

# Verify the JAR was created
ls -la target/*.jar

Output:

-rw-r--r-- 1 user user 45M Dec  1 10:30 my-spring-app-1.0.0.jar

Configuration Verification Checklist

  • ✓ Created application.properties, application-dev.properties, and application-prod.properties
  • ✓ Application starts successfully with development profile
  • ✓ Executable JAR builds without errors
  • ✓ Database dependencies configured in build file
  • ✓ Environment variable syntax working in production profile

Key Benefits Achieved

Development Benefits

  • Local development database
  • Debug logging enabled
  • Fast development cycle
  • Easy configuration changes

Production Benefits

  • Secure credential management
  • Optimized performance settings
  • Environment-specific configurations
  • Cloud-ready deployment package

What’s Next?

Coming Up in Step 2:

  • Create AWS Lightsail instance
  • Configure Linux environment
  • Set up MySQL database
  • Prepare for application deployment

Your Spring Boot application is now production-ready with proper profile configuration!

Summary

  • Spring Boot profiles enable environment-specific configurations
  • Environment variables provide secure credential management
  • Executable JARs simplify deployment processes
  • Proper configuration is essential for cloud deployments

Your application is now ready for AWS Lightsail deployment!