Skip to content

Introduce ModuleResource for resources loaded from a given Module #28507

Closed

Description

@sbrannen

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.

Activity

  1. added
    in: core
    type: enhancement
    on May 23, 2022
  2. added this to the 6.0.0-M5 milestone on May 23, 2022
  3. self-assigned this
    on May 23, 2022
  4. modified the milestones: 6.0.0-M5, 6.0.0-M6 on Jun 20, 2022
  5. modified the milestones: 6.0.0-M6, 6.0.0-RC1 on Aug 29, 2022
  6. modified the milestones: 6.0.0-RC1, 6.0.0-RC2 on Oct 10, 2022
  7. modified the milestones: 6.0.0-RC2, 6.0.x on Oct 18, 2022
  8. modified the milestones: 6.0.x, 6.1.0-M1 on Mar 7, 2023
  9. modified the milestones: 6.1.0-M1, 6.1.0-M2 on Jun 13, 2023
  10. 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
  11. jhoeller commented on Jun 29, 2023

    @jhoeller
    Contributor

    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.

  12. 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
  13. added a commit that references this issue on Sep 9, 2024
    6061fdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions