Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 1.51 KB

File metadata and controls

36 lines (24 loc) · 1.51 KB
name spring-resource-sample
description Spring ResourceLoader sample that reads BLOB-backed resources from Oracle AI Database.
tags
Database
Java
SpringBoot
blog_post https://andersswanson.dev/2025/05/29/dynamically-load-spring-properties-from-external-repositories/

Spring Resource Loader Example

This example demonstrates how to implement a custom Spring Resource Loader to idiomatically load blob resources (such as images or files) at application startup from an arbitrary storage backend.

In this example our storage backend is an Oracle AI Database table using a BLOB column, but the design applies to any storage backend with a programmable API.

  • DatabaseResource.java defines custom Resource type extending AbstractResource
  • DatabaseResourceResolver.java implements the Spring ResourceLoaderAware and ProtocolResolver interfaces to provide a Spring Compnent capable of instantiating DatabaseResorce objects.
  • DatabaseLocation.java is a data class that maps a Resource location to a BLOB in the database.

Prerequisites

  • Java 21+, Maven

Run the sample

The sample provides an all-in-one test leveraging Testcontainers and Oracle AI Database to do the following:

  1. Start and configure a database server using Testcontainers
  2. Load Spring Resources from the database
  3. Verify the resources are loaded and accessible

You can run the test like so, from the project's root directory:

mvn test