Skip to main content

Overview

This page provides a comprehensive reference for all configuration properties used by the Library Management API. The main configuration file is located at:
src/main/resources/application.properties

Complete Properties File

spring.application.name=training

# PostgreSQL Database Configuration
spring.datasource.url=${db_url}
spring.datasource.username=${db_username}
spring.datasource.password=${db_password}

# PostgreSQL Driver
spring.datasource.driver-class-name=org.postgresql.Driver

# Hibernate/JPA Configurations
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=create-drop

server.port=8081

security.jwt.user.generator=${user_jwt}
security.jwt.key.private=${key_jwt}

Properties Reference

Application Properties

spring.application.name
string
default:"training"
The name of the Spring Boot application. This appears in logs and actuator endpoints.Location: application.properties:1

Server Properties

server.port
integer
default:"8081"
required
The HTTP port on which the application listens for requests.Default: 8081
Location: application.properties:15
Change this value if port 8081 is already in use or for different environments:
# Development
server.port=8081

# Production
server.port=8080

Database Properties

Database credentials must be provided via environment variables. The application will fail to start if these are not set.
spring.datasource.url
string
required
PostgreSQL JDBC connection URL. Must be provided via the db_url environment variable.Environment Variable: db_url
Location: application.properties:4
Format:
jdbc:postgresql://<host>:<port>/<database_name>[?<options>]
Examples:
# Local development
jdbc:postgresql://localhost:5432/library_db

# Docker
jdbc:postgresql://postgres:5432/library_db

# Production with SSL
jdbc:postgresql://prod-db.example.com:5432/library_db?sslmode=require
spring.datasource.username
string
required
Database username for authentication. Must be provided via the db_username environment variable.Environment Variable: db_username
Location: application.properties:5
Example:
export db_username="postgres"
spring.datasource.password
string
required
Database password for authentication. Must be provided via the db_password environment variable.Environment Variable: db_password
Location: application.properties:6
Never commit database passwords to version control. Use environment variables or secret management systems.
spring.datasource.driver-class-name
string
default:"org.postgresql.Driver"
JDBC driver class for PostgreSQL database connectivity.Value: org.postgresql.Driver
Location: application.properties:9
This driver is provided by the postgresql dependency in pom.xml.

JPA/Hibernate Properties

spring.jpa.database-platform
string
default:"org.hibernate.dialect.PostgreSQLDialect"
Hibernate dialect for PostgreSQL-specific SQL generation and optimizations.Value: org.hibernate.dialect.PostgreSQLDialect
Location: application.properties:12
This dialect enables PostgreSQL-specific features like:
  • Native UUID support
  • Array types
  • JSON/JSONB columns
  • PostgreSQL-specific functions
spring.jpa.hibernate.ddl-auto
string
default:"create-drop"
Database schema generation strategy.Default: create-drop
Location: application.properties:13
The default create-drop value is only for development. All data is lost when the application stops.
Available Values:
ValueBehaviorUse Case
create-dropCreates schema on startup, drops on shutdownDevelopment/Testing
createCreates schema on startup, keeps on shutdownDevelopment
updateUpdates schema to match entitiesDevelopment
validateValidates schema, no modificationsProduction
noneNo schema managementProduction
Recommended Production Setting:
spring.jpa.hibernate.ddl-auto=validate

Security Properties

JWT security properties must be configured via environment variables to prevent exposing secrets in version control.
security.jwt.user.generator
string
required
JWT token issuer identifier. Used in the iss claim of generated tokens.Environment Variable: user_jwt
Location: application.properties:17
Used In: JwtUtils.java:31
Example:
export user_jwt="library-management-api"
This value is validated when tokens are verified to ensure they were issued by this API.
security.jwt.key.private
string
required
Secret key used to sign and verify JWT tokens using HMAC256 algorithm.Environment Variable: key_jwt
Location: application.properties:18
Used In: JwtUtils.java:34
  • Must be at least 256 bits (32 characters) for security
  • Must be kept secret and never committed to version control
  • Should be rotated periodically in production
Generating a Secure Key:
# Generate a random 256-bit key (Linux/macOS)
openssl rand -base64 32

# Example output
export key_jwt="7x!A%D*G-KaNdRgUkXp2s5v8y/B?E(H+"

Environment-Specific Configuration

Development Environment

# Database
export db_url="jdbc:postgresql://localhost:5432/library_dev"
export db_username="postgres"
export db_password="admin"

# JWT
export user_jwt="library-api-dev"
export key_jwt="dev-secret-key-change-in-production"

# Start application
./mvnw spring-boot:run

Production Environment

# Database (from secret management)
export db_url="jdbc:postgresql://prod-db.internal:5432/library_prod?sslmode=require"
export db_username="library_service"
export db_password="${DB_PASSWORD_FROM_VAULT}"

# JWT (from secret management)
export user_jwt="library-management-api"
export key_jwt="${JWT_SECRET_FROM_VAULT}"

Testing Environment

application-test.properties
spring.application.name=training-test

# Use H2 in-memory database for tests
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

# H2 Dialect
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create-drop

# Different port to avoid conflicts
server.port=0

# Test JWT configuration
security.jwt.user.generator=test-api
security.jwt.key.private=test-secret-key-for-testing-only

Additional Configuration Options

Logging Configuration

Add these properties to control logging levels:
# Root logging level
logging.level.root=INFO

# Application logging
logging.level.com.raven.training=DEBUG

# Spring Security logging
logging.level.org.springframework.security=DEBUG

# Hibernate SQL logging
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

# Format SQL
spring.jpa.properties.hibernate.format_sql=true

Connection Pool Configuration

Optimize database connection pooling:
# HikariCP settings
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.idle-timeout=600000
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.pool-name=LibraryHikariPool

Performance Tuning

# JPA performance settings
spring.jpa.properties.hibernate.jdbc.batch_size=20
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true

# Second-level cache (if using)
spring.jpa.properties.hibernate.cache.use_second_level_cache=false
spring.jpa.properties.hibernate.cache.use_query_cache=false

API Documentation Configuration

# Swagger/OpenAPI settings
springdoc.api-docs.path=/v3/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.swagger-ui.enabled=true
springdoc.packages-to-scan=com.raven.training.controller

Validation and Troubleshooting

Verifying Configuration

Check that all required environment variables are set:
#!/bin/bash

required_vars=("db_url" "db_username" "db_password" "user_jwt" "key_jwt")

for var in "${required_vars[@]}"; do
    if [ -z "${!var}" ]; then
        echo "ERROR: $var is not set"
        exit 1
    else
        echo "✓ $var is set"
    fi
done

echo "All required environment variables are configured"

Common Configuration Errors

Error: Error creating bean with name 'dataSource'Cause: Required database environment variables not setSolution:
export db_url="jdbc:postgresql://localhost:5432/library_db"
export db_username="postgres"
export db_password="yourpassword"
Error: JWTVerificationExceptionCause: security.jwt.key.private mismatch between environmentsSolution: Ensure the same JWT secret is used across all instances:
# Verify the key is set
echo $key_jwt
Error: Port 8081 is already in useSolution: Change the server port:
server.port=8082
Or set via environment variable:
export SERVER_PORT=8082
Error: Schema validation failuresCause: Using create-drop in productionSolution: Change DDL auto mode:
spring.jpa.hibernate.ddl-auto=validate

Configuration Hierarchy

Spring Boot loads configuration in the following order (later sources override earlier ones):
  1. Default properties in application.properties
  2. Profile-specific properties (application-{profile}.properties)
  3. Environment variables
  4. Command-line arguments
Example Override:
# Override via environment variable
export SPRING_JPA_HIBERNATE_DDL_AUTO=validate

# Override via command line
java -jar app.jar --server.port=9090

Build docs developers (and LLMs) love