A small Spring Boot demo application that fetches stock quote data and exposes a simple HTTP API to return quotes. The project also uses jOOQ for database code generation and Flyway for database migrations. Testcontainers are used in the Gradle build to provide a PostgreSQL instance for jOOQ generation and tests.
- Exposes a REST endpoint to fetch stock quotes (
GET /quotes). - Delegates external stock-data lookups to a REST client (
QuoteClient) that calls an external stock-data provider. - Uses Flyway for database migrations (SQL migration files live under
src/main/resources/db/migration). - Uses jOOQ to generate Java classes from the database schema. The generated sources are placed under
build/generated-src/jooqand compiled with the project.
src/main/java/com/kiran/musicapi- application codeMusicapiApplication.java- Spring Boot entrypointconfig/- Spring configuration classes and propertiesstockdata/api/- client interfaces and DTOs used to call and model the third-party stock-data APIresources/StockDataResource.java- exposesGET /quotesclient/QuoteClient.java- JAX-RS-style interface for the remote APIcontract/- DTOs:StockApiResponse,Quote,Meta
src/main/resources/db/migration- Flyway SQL migrationsbuild.gradle- Gradle build logic: testcontainers + Flyway + jOOQ integration
- Description: Returns a
StockApiResponsecontaining metadata and a map of ticker symbols toQuoteobjects. - Path:
/quotes - Produces: application/json
- Example (simplified):
{ "meta": { /* ... */ }, "data": { "NVDA": { "ticker": "NVDA", "price": 420.12, "volume": 123456, /* ... */ }, "AAPL": { /* ... */ } } }
The StockDataResource currently requests the symbols NVDA,MSFT,AAPL by default. The client wiring uses QuoteClient and QuoteClientRequestFilter to attach the configured API token.
Application-level configuration is in src/main/resources/application.properties.
Key properties:
server.port— HTTP port for the Spring Boot app (default8888in the repo)quote-client.base-url— base URL for the external stock-data APIspring.datasource.*— defaults for a local Postgres instance. During jOOQ generation the Gradle script starts a Testcontainers Postgres and points jOOQ / Flyway at that container.
Sensitive values (like the external API token) should be provided via environment variables or an external properties file in production.
This project invokes a Testcontainers PostgreSQL instance from the Gradle script and runs Flyway migrations before jOOQ generation. The generated sources are written into build/generated-src/jooq and added to the main source set so compileJava includes them.
By default the generateJooq step is wired into the build but may be gated behind a Gradle project property. To force jOOQ generation during the compile phase use the following command from the project root (Windows PowerShell):
cd /d D:\Work\Java\musicapi\musicapi
./gradlew.bat clean classes -PgenerateJooq=trueNotes & troubleshooting when generating jOOQ:
- The Gradle script starts a PostgreSQL Testcontainer and runs Flyway migrations inside the Gradle JVM. If Flyway complains it cannot handle the JDBC URL ("No database found to handle jdbc:postgresql://..."), it usually means the PostgreSQL JDBC driver is not available to the Gradle buildscript classpath. Ensure
org.postgresql:postgresqlis present on the buildscript/plugin classpath. The repo already includes this in thebuild.gradlebuildscript classpath. - If you change buildscript classpath dependencies, stop the Gradle daemon before re-running to ensure the daemon picks up new classpath entries:
./gradlew.bat --stop
./gradlew.bat clean classes -PgenerateJooq=true --no-daemon -i- If jOOQ generation fails, inspect the Gradle output for the printed
jdbc url:line (the Gradle script prints the Testcontainer JDBC URL before running Flyway). Use that URL to confirm connectivity with external tools if needed.
- Build and run tests:
./gradlew.bat clean test- Run the application locally (after building):
./gradlew.bat bootRun- Generate jOOQ classes and compile (explicit property):
./gradlew.bat clean classes -PgenerateJooq=true- Keep
application.propertiesvalues for local development, but use environment variables or secret stores for tokens and production DB credentials. - When debugging Flyway/jOOQ in the Gradle script, enable Gradle info/trace logging to view classpath and Flyway logs (
-ior--stacktrace/--debug).
- SQL migrations:
src/main/resources/db/migration - jOOQ configuration:
build.gradle(thejooqblock and thetasks.withType(nu.studer.gradle.jooq.JooqGenerate)configuration) - REST client wiring:
config/StockdataConfig.javaandstockdata/api/client
If you want, I can:
- Add example cURL commands for the
/quotesendpoint. - Add a small
READMEsection describing how to supply thequote-client.api-tokensecurely for local testing. - Run the Gradle jOOQ generation task here and paste logs (if you want me to run it).
Generated on 2025-10-13.