As a follow up to #28506, we should introduce ModulePathResource
as companion to the existing ClassPathResource
to support use cases when a developer wishes to explicitly load a resource from the module path instead of the class path.
Comment From: jhoeller
Revisiting the module topic from another angle, I came back to the topic of module resource access and therefore to this issue.
It turns out that the module system provides no entry point for general module path access. In order to find an arbitrary resource on the module path, we'd effectively have to perform a full search through all modules like with #28506. For that reason, we cannot provide a proper (efficient enough) equivalent to ClassPathResource
.
Practically, module-contained resources can be retrieved via Class.getResource
on a Class from a given module, equivalent to a ClassPathResource(String, Class)
setup. Alternatively, they can also be retrieved via Module.getResourceAsStream
on a given Module
instance, coming either from ModuleLayer.findModule
or simply Class.getModule()
.
For the latter scenario, a Spring-provided ModuleResource
seems sensible, based on a Module
reference and a String path. I've sketched this out locally and figured I'd take it forward under this issue. However, since this is not really a "module path" resource but rather a module-bound resource, let's name it ModuleResource
instead.