The Ecommerce Order Service uses Spring Boot’s configuration system with environment-specific YAML files.
Configuration Files
Configuration is split across multiple files:
src/main/resources/
├── application.yml # Default configuration
├── application-dev.yml # Development environment
└── application-ci.yml # CI/CD environment
Active Profile
Set the active Spring profile using:
export SPRING_PROFILES_ACTIVE=dev
Database Configuration
MySQL connection settings from application-dev.yml:
spring:
datasource:
url: jdbc:mysql://localhost:13306/ecommerce_order_mysql?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&connectionCollation=utf8mb4_bin&useServerPrepStmts=false&rewriteBatchedStatements=true
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: root
Connection Properties
JDBC connection URL for MySQL databaseComponents:
- Host:
localhost
- Port:
13306 (non-standard to avoid conflicts)
- Database:
ecommerce_order_mysql
Query Parameters:
allowMultiQueries=true - Enables multiple SQL statements
useUnicode=true - Unicode character support
characterEncoding=UTF-8 - UTF-8 encoding
connectionCollation=utf8mb4_bin - Binary collation for case-sensitive comparisons
useServerPrepStmts=false - Disables server-side prepared statements
rewriteBatchedStatements=true - Optimizes batch inserts
MySQL JDBC driver class: com.mysql.cj.jdbc.Driver
Database username (default: root)
Database password (default: root)
Environment-Specific Settings
Development
CI/CD
Production
spring:
datasource:
url: jdbc:mysql://localhost:13306/ecommerce_order_mysql?...
username: root
password: root
Uses local MySQL started via Docker Compose.Configure in application-ci.yml for your CI environment:spring:
datasource:
url: jdbc:mysql://ci-db-host:3306/ecommerce_order_mysql?...
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
Use environment variables for credentials. Create application-prod.yml:spring:
datasource:
url: jdbc:mysql://${DB_HOST}:${DB_PORT}/ecommerce_order_mysql?...
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
hikari:
maximum-pool-size: 20
minimum-idle: 5
connection-timeout: 30000
Add connection pool tuning for production.
RabbitMQ Configuration
Event publishing is configured via OrderRabbitmqConfig:
@Configuration
public class OrderRabbitmqConfig {
@Bean
public Binding bindToInventoryChanged() {
return new Binding(
properties.getReceiveQ(),
QUEUE,
"order-publish-x", // Exchange name
"com.ecommerce.order.sdk.event.order.#", // Routing key
null
);
}
}
RabbitMQ Properties
Configure RabbitMQ connection in your YAML:
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
virtual-host: /
ecommerce:
rabbitmq:
receiveQ: order-receive-queue
exchange: order-publish-x
spring.rabbitmq.host
string
default:"localhost"
RabbitMQ server hostname
ecommerce.rabbitmq.exchange
string
default:"order-publish-x"
Exchange name for publishing order events
ecommerce.rabbitmq.receiveQ
Queue name for receiving events (CQRS pattern)
Application Properties
Custom application configuration:
ecommerce:
order:
jwtSecret: whateversecret
jwtExpireMinutes: 30
ecommerce.order.jwtSecret
Secret key for JWT token generation and validationUse a strong secret in production. The development value is for testing only.
ecommerce.order.jwtExpireMinutes
JWT token expiration time in minutes
Logging Configuration
Log File Location
logging:
file: /var/log/ecommerce-order-backend/order-dev.log
Log Levels
Configure log levels for different packages:
logging:
level:
root: INFO
com.ecommerce.order: DEBUG
org.springframework.web: DEBUG
org.hibernate.SQL: DEBUG
org.hibernate.type.descriptor.sql.BasicBinder: TRACE
logging.level.com.ecommerce.order
Log level for order service code (TRACE, DEBUG, INFO, WARN, ERROR)
logging.level.org.hibernate.SQL
Set to DEBUG to see SQL queries
The service exposes build metadata via /about endpoint. These values are injected during build:
buildNumber: ${buildNumber}
buildTime: ${buildTime}
gitRevision: ${gitRevision}
gitBranch: ${gitBranch}
appName: ${appName}
These placeholders are replaced by the gradle/version-info.gradle script during build.
Docker Compose Configuration
Local MySQL is configured via Docker Compose:
gradle/docker-compose/docker-compose.yml
version: '3'
services:
mysql:
image: mysql:8.0
ports:
- "13306:3306"
environment:
MYSQL_DATABASE: ecommerce_order_mysql
MYSQL_ROOT_PASSWORD: root
Manage with Gradle tasks:
# Start MySQL
./gradlew composeUp
# Stop MySQL (preserves data)
./gradlew composeDown
# View logs
./gradlew composeLog
Environment Variables
For production deployments, use environment variables:
export DB_HOST=prod-mysql.example.com
export DB_PORT=3306
export DB_USERNAME=order_service
export DB_PASSWORD=secure_password
Reference in YAML:spring:
datasource:
url: jdbc:mysql://${DB_HOST}:${DB_PORT}/ecommerce_order_mysql
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
export RABBITMQ_HOST=prod-rabbitmq.example.com
export RABBITMQ_PORT=5672
export RABBITMQ_USERNAME=order_service
export RABBITMQ_PASSWORD=secure_password
export JWT_SECRET=your_256_bit_secret_key_here
ecommerce:
order:
jwtSecret: ${JWT_SECRET}
Configuration Properties Class
Custom properties are bound to a configuration class:
@Configuration
@ConfigurationProperties(prefix = "ecommerce.order")
@Data
public class OrderProperties {
private String jwtSecret;
private int jwtExpireMinutes;
}
Access properties via dependency injection:
@Service
public class SomeService {
@Autowired
private OrderProperties properties;
public void doSomething() {
String secret = properties.getJwtSecret();
}
}
Best Practices
- Never commit secrets - Use environment variables or secret management systems
- Use profiles - Separate configuration for dev, staging, production
- Override via environment - Use
SPRING_DATASOURCE_URL to override spring.datasource.url
- Validate on startup - Use
@Validated on configuration classes
- Document defaults - Comment all custom properties
Next Steps
Testing
Learn about the testing strategy
Deployment
Deploy to production