I have a small micronaut application where I need to serve files inside resources
. Those files should be publicly accessible, so if I enter the url for that file, it would open directly in the browser (they are small images).
I tried using
micronaut:
application:
name: myapp
router.static-resources:
enabled: true
paths: classpath:data
mapping: "/**"
but the response is always the same:
{
"message": "Page Not Found",
"_links": {
"self": {
"href": "/data/per.svg",
"templated": false
}
}
}
What additional configuration do I need?
There are two issues in your configuration:
micronaut.router.static-resources.enabled
but it should bemicronaut.router.static-resources.default.enabled
. So thedefault
is missing.But it is better to use separate context then root to prevent conflict with controller paths. So, you can map it to static for example:
Then you can access it on http://localhost:8080/static/per.svg