Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ModuleResource for resources loaded from a given Module #28507

Closed
sbrannen opened this issue May 23, 2022 · 1 comment
Closed

Introduce ModuleResource for resources loaded from a given Module #28507

sbrannen opened this issue May 23, 2022 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

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.

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels May 23, 2022
@sbrannen sbrannen added this to the 6.0.0-M5 milestone May 23, 2022
@sbrannen sbrannen self-assigned this May 23, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-M5, 6.0.0-M6 Jun 20, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-M6, 6.0.0-RC1 Aug 29, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-RC1, 6.0.0-RC2 Oct 10, 2022
@sbrannen sbrannen modified the milestones: 6.0.0-RC2, 6.0.x Oct 18, 2022
@jhoeller jhoeller modified the milestones: 6.0.x, 6.1.0-M1 Mar 7, 2023
@jhoeller jhoeller modified the milestones: 6.1.0-M1, 6.1.0-M2 Jun 13, 2023
@sbrannen sbrannen changed the title Introduce ModulePathResource for resources loaded from the module path Introduce ModulePathResource for resources loaded from the module path Jun 13, 2023
@jhoeller
Copy link
Contributor

jhoeller commented 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.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.

@jhoeller jhoeller changed the title Introduce ModulePathResource for resources loaded from the module path Introduce ModuleResource for resources loaded from a given Module Jun 29, 2023
@jhoeller jhoeller assigned jhoeller and unassigned sbrannen Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants