| name | spring-cloud-config | ||||
|---|---|---|---|---|---|
| description | Spring Cloud Config sample that stores configuration properties in Oracle AI Database. | ||||
| tags |
|
||||
| blog_post | https://andersswanson.dev/2025/11/21/spring-cloud-config-jdbc-backend-oracle-ai-database/ |
This module demonstrates how to use Oracle AI Database as the backend for a Spring Cloud Config Server. It includes a config server that stores configuration properties in an Oracle AI Database via JDBC, a simple client application that consumes these configurations, and a Docker Compose setup for the database.
- Java 21 or later
- Maven
- Docker (for running the Oracle AI Database container)
- client/: The Spring Boot client application that fetches configurations from the server.
- server/: The Spring Cloud Config Server application with JDBC backend.
- oracle/: Initialization scripts for the database (e.g., grant_permissions.sql to create user and PROPERTIES table).
- docker-compose.yml: Docker Compose file to spin up an Oracle AI Database instance.
- crud-properties.md: Additional documentation on using the CRUD API for managing properties.
-
Start the Oracle AI Database: Run the Docker Compose file to start the Oracle Free container:
docker-compose up -dThis sets up the database on
localhost:1527with PDBfreepdb1. Admin password isWelcome12345. The init script inoracle/grant_permissions.sqlcreates thetestuseruser (password:testpwd) and thePROPERTIEStable for Spring Cloud Config. -
Build and Run the Config Server: Navigate to the
serverdirectory and run:mvn clean compile spring-boot:runThe server runs on
http://localhost:8888(configured inserver/src/main/resources/application.yaml). It uses JDBC to connect to the database atjdbc:oracle:thin:@localhost:1527/freepdb1with credentialstestuser/testpwd. -
Insert Configuration Properties: Use SQL or the optional CRUD API (exposed at
/api/properties) to add properties to thePROPERTIEStable. Example row:- ID: 1
- APPLICATION: 'myapp'
- PROFILE: 'dev'
- LABEL: 'latest'
- PROP_KEY: 'config.key'
- VALUE: 'config-value'
The server's custom SQL query is:
SELECT PROP_KEY, VALUE from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?.
curl -X POST http://localhost:8888/api/properties \
-H "Content-Type: application/json" \
-d '{
"application": "myapp",
"profile": "dev",
"label": "latest",
"propKey": "config.key",
"value": "config-value"
}'- Build and Run the Client:
Navigate to the
clientdirectory and run:The client is configured (inmvn clean compile spring-boot:runclient/src/main/resources/application.yaml) to fetch fromhttp://localhost:8888with application namemyappand active profiledev. It injects${config.key}inController.java.
-
Test Config Fetch: Once the client is running (default port 8080), access:
curl http://localhost:8080/valueThis should return the value from the config server, e.g., "This is my config value: config-value".
-
Manage Properties via CRUD API (Optional): The
PropertiesControllerin the server provides REST endpoints at/api/propertiesfor CRUD operations. Seecrud-properties.mdfor curl examples.
- Ensure the database container is healthy (check
docker logs configdb). - Verify properties in the database match the client's application, profile, and label.
- Check server logs for JDBC connection errors.
- If properties aren't resolving, test the config endpoint directly:
curl http://localhost:8888/myapp/dev/latest.
For more details, see the Spring Cloud Config documentation: https://docs.spring.io/spring-cloud-config/docs/current/reference/html/.