Skip to main content
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:
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

url
string
required
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
driverClassName
string
required
MySQL JDBC driver class: com.mysql.cj.jdbc.Driver
username
string
required
Database username (default: root)
password
string
required
Database password (default: root)

Environment-Specific Settings

spring:
  datasource:
    url: jdbc:mysql://localhost:13306/ecommerce_order_mysql?...
    username: root
    password: root
Uses local MySQL started via Docker Compose.

RabbitMQ Configuration

Event publishing is configured via OrderRabbitmqConfig:
OrderRabbitmqConfig.java
@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
spring.rabbitmq.port
integer
default:"5672"
RabbitMQ AMQP port
ecommerce.rabbitmq.exchange
string
default:"order-publish-x"
Exchange name for publishing order events
ecommerce.rabbitmq.receiveQ
string
Queue name for receiving events (CQRS pattern)

Application Properties

Custom application configuration:
application-dev.yml
ecommerce:
  order:
    jwtSecret: whateversecret
    jwtExpireMinutes: 30
ecommerce.order.jwtSecret
string
required
Secret key for JWT token generation and validation
Use a strong secret in production. The development value is for testing only.
ecommerce.order.jwtExpireMinutes
integer
default:"30"
JWT token expiration time in minutes

Logging Configuration

Log File Location

application-dev.yml
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
string
default:"INFO"
Log level for order service code (TRACE, DEBUG, INFO, WARN, ERROR)
logging.level.org.hibernate.SQL
string
default:"INFO"
Set to DEBUG to see SQL queries

Build Information

The service exposes build metadata via /about endpoint. These values are injected during build:
application-dev.yml
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:
OrderProperties.java
@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

  1. Never commit secrets - Use environment variables or secret management systems
  2. Use profiles - Separate configuration for dev, staging, production
  3. Override via environment - Use SPRING_DATASOURCE_URL to override spring.datasource.url
  4. Validate on startup - Use @Validated on configuration classes
  5. Document defaults - Comment all custom properties

Next Steps

Testing

Learn about the testing strategy

Deployment

Deploy to production

Build docs developers (and LLMs) love