Overview
The User Management System uses Spring Boot profiles to manage environment-specific configurations. You can switch between development and production environments by setting the active profile.Profile Selection
The active profile is configured inapplication.properties:
application.properties
Available Profiles
- Development
- Production
The development profile (Features:
dev) uses an in-memory H2 database and includes debugging features.- H2 in-memory database
- SQL logging enabled
- H2 console accessible at
/h2-console - Auto-initialization with sample data
- Development JWT secret
Switching Profiles
Method 1: Application Properties
Editsrc/main/resources/application.properties:
Method 2: Environment Variable
Set theSPRING_PROFILES_ACTIVE environment variable:
Method 3: Command Line Argument
Pass the profile as a command line argument:Method 4: Maven/Gradle
Run with Maven:Environment Variables
Environment variables override properties file values and are recommended for sensitive configuration like database passwords and JWT secrets.
Common Environment Variables
| Variable | Description | Example |
|---|---|---|
SPRING_PROFILES_ACTIVE | Active profile | prod |
SPRING_DATASOURCE_URL | Database connection URL | jdbc:mysql://localhost:3306/user_management |
SPRING_DATASOURCE_USERNAME | Database username | dbuser |
SPRING_DATASOURCE_PASSWORD | Database password | securepassword |
JWT_SECRET | JWT signing secret | your-256-bit-secret |
JWT_EXPIRATION | Token expiration in ms | 86400000 (24 hours) |
Application Properties
Base Configuration
These properties are shared across all profiles:Profile-Specific Files
Create profile-specific configuration files:application-dev.properties- Development configurationapplication-prod.properties- Production configurationapplication-{custom}.properties- Custom profile configuration
application.properties.
Best Practices
- Never commit secrets - Use environment variables for sensitive data
- Use dev profile locally - Keep the in-memory database for development
- Externalize production config - Store production properties outside the JAR
- Validate on startup - Ensure required properties are set before the application starts
- Document custom properties - Maintain clear documentation for any custom configuration