Database Configuration
1. Overview
The Service API uses an external relational database to store application data, including transaction records, device information, and user credentials.
The application supports MySQL and Oracle database systems, provided that the appropriate JDBC driver is included in the project dependencies (for example, com.mysql.cj.jdbc.Driver or oracle.jdbc.OracleDriver).
The application does not create this database; it relies on an existing instance configured and maintained externally or manually via SQL scripts provided with the application.
Spring Boot configuration properties are used to define the data source for application-level persistence. These properties are automatically recognized by Spring without requiring additional setup.
The database is designed to be lightweight and focused on the core functionality of the Service API.
2. Configuration
Service API now ships two dedicated Spring profiles: application-mysql.yml and application-oracle.yml.
Select the profile through SPRING_PROFILES_ACTIVE (or spring.profiles.active) and Spring Boot will load one of the following configurations.
2.1. MySQL Profile
spring:
datasource:
jdbc-url: ${MYSQL_JDBC_URL:jdbc:mysql://${MYSQL_HOST:${DB_HOST:localhost}}:${MYSQL_PORT:3306}/${MYSQL_SCHEMA:ftacs}?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC}
username: ${MYSQL_USER:ftacs}
password: ${MYSQL_PASSWORD:ftacs}
driver-class-name: ${MYSQL_DRIVER_CLASS_NAME:com.mysql.cj.jdbc.Driver}
hikari:
maximum-pool-size: ${DB_MAX_POOL_SIZE:10}
minimum-idle: ${DB_MIN_IDLE:5}
connection-timeout: ${DB_CONNECTION_TIMEOUT_MS:30000}
2.2. Oracle Profile
spring:
datasource:
jdbc-url: ${ORACLE_JDBC_URL:jdbc:oracle:thin:@//${ORACLE_HOST:${DB_HOST:localhost}}:${ORACLE_PORT:1521}/${ORACLE_SERVICE:XEPDB1}}
username: ${ORACLE_USER:ftacs}
password: ${ORACLE_PASSWORD:ftacs}
driver-class-name: ${ORACLE_DRIVER_CLASS_NAME:oracle.jdbc.OracleDriver}
hikari:
maximum-pool-size: ${DB_MAX_POOL_SIZE:10}
minimum-idle: ${DB_MIN_IDLE:5}
connection-timeout: ${DB_CONNECTION_TIMEOUT_MS:30000}
2.3. Environment Variables
2.3.1. Shared pool settings
| Variable | Description |
|---|---|
|
Upper bound for the datasource pool. Default |
|
Minimum warm connections in the pool. Default |
|
How long to wait for a connection before failing a request. Default |
|
Fallback hostname used by the profile-specific variables. |
2.3.2. MySQL profile variables
| Variable | Description |
|---|---|
|
Full JDBC override. Leave empty to synthesize one from host/port/schema. |
|
Hostname and port of the MySQL server. Defaults: |
|
Schema name for the Service API tables. Default |
|
Credentials for the database. Default |
|
JDBC driver class ( |
2.3.3. Oracle profile variables
| Variable | Description |
|---|---|
|
Full Oracle JDBC string ( |
|
Listener endpoint. Defaults: |
|
Oracle service or SID. Default |
|
Credentials for the database. Default |
|
JDBC driver class ( |
3. Defining DataSource Bean
A @Configuration class defines the datasource bean using HikariCP:
@Configuration
public class DatabaseConfig {
@Primary
@Bean
@ConfigurationProperties("spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
}
The dataSource bean is configured with properties under spring.datasource.* and marked with @Primary to be the default data source for the application.