You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Introduce ModuleResource for resources loaded from a given Module #28507
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.
changed the title [-]Introduce ModulePathResource for resources loaded from the module path[/-][+]Introduce `ModulePathResource` for resources loaded from the module path[/+]on Jun 13, 2023
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.
changed the title [-]Introduce `ModulePathResource` for resources loaded from the module path[/-][+]Introduce `ModuleResource` for resources loaded from a given `Module`[/+]on Jun 29, 2023
Activity
[-]Introduce ModulePathResource for resources loaded from the module path[/-][+]Introduce `ModulePathResource` for resources loaded from the module path[/+]jhoeller commentedon Jun 29, 2023
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.getResourceon a Class from a given module, equivalent to aClassPathResource(String, Class)setup. Alternatively, they can also be retrieved viaModule.getResourceAsStreamon a givenModuleinstance, coming either fromModuleLayer.findModuleor simplyClass.getModule().For the latter scenario, a Spring-provided
ModuleResourceseems sensible, based on aModulereference 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 itModuleResourceinstead.[-]Introduce `ModulePathResource` for resources loaded from the module path[/-][+]Introduce `ModuleResource` for resources loaded from a given `Module`[/+]Additional notes on module access via ClassPathResource
Additional notes on module access via ClassPathResource
Support for getFilename() in ModuleResource
Introduce ModuleResource for resources loaded from a given Module