Results 1 to 3 of 3

Thread: Adding ResourceHandlers at runtime

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    1

    Default Adding ResourceHandlers at runtime

    Hello

    I have a Spring 3.1 MVC application with a multi-tenant design (multiple customers supported by one application). Each customer has their own ResourceHandler mapping for static resource paths (CSS files etc.). These ResourceHandlers are added programatically in a WebMvcConfigurerAdapter subclass (based on directories on disk), via addResourceHandlers(ResourceHandlerRegistry registry). This is all annotation driven.

    I would like to add support for updating the customer resource path mappings at runtime via an "admin" controller. The problem I have is that I'm not sure how to get access to the WebMvcConfigurerAdapter subclass instance in my controller, or how to access the ResourceHandlerRegistry instance in order to call addResourceHandlers.

    Any pointers much appreciated.
    Richard

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Adding them to the registry is useless, this is only used at configuration time not at runtime. You would need to register your handler with the SimpleUrlHandlerMapping that is used to register the already available ResourceHandlers. The latter you can simply get injected.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    It would be better if you could figure out what resource mappings you need at startup.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •