In this demo I show have you can use Micronaut's Readable interface to load resources from either the classpath, or the filesystem in an implementation agnostic fashion.
git clone https://github.com/ghillert/resource-readable-demo.git
./cd resource-readable-demo
./mvnw mn:run
./mvnw clean package
java -jar target/resource-readable-demo-0.1.jar --images.image-file=file:/Users/hillert/Desktop/end-of-springone-2020.jpg
The following 2 REST API endpoints are available:
If you like to override the property for the single image images.image-file
and
load an image from the file-system instead, you can do that e.g. with:
java -jar target/resource-readable-demo-0.1.jar --images.image-file=file:/my/path/to/some/awesome-image.jpg
or
./mvnw mn:run -Dmn.appArgs="--images.image-file=file:/my/path/to/some/awesome-image.jpg"
The main configuration of the demo is in application.yml
:
micronaut:
application:
name: Micronaut Readable Demo
images:
image-file: "classpath:images/bismarckia-nobilis.jpg"
# image-file: "file:/path/to/images/bismarckia-nobilis.jpg"
other-files:
- "classpath:images/bismarckia-nobilis.jpg"
- "classpath:images/bamboo.jpg"
- "classpath:images/hibiscus.jpg"