[BLOSSOM-230] Module class bean properties as PropertySource Created: 01/Mar/16  Updated: 29/Jun/18  Resolved: 29/Apr/16

Status: Closed
Project: Blossom
Component/s: blossom-spring-loaded
Affects Version/s: 3.1.2
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Samuel Zihlmann Assignee: Tobias Mattsson
Resolution: Not an issue Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to BLOSSOM-229 Add ApplicationContextInitializer Sup... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Date of First Response:
Visible to:
Peter Mohn

 Description   

Having module class bean properties (JCR) available as Property Source would be a nice improvement. My current implementation is using a ApplicationContextInitializer to achieve this.
https://documentation.magnolia-cms.com/display/DOCS/Module+configuration

public class MyContextInitializer implements ApplicationContextInitializer<AnnotationConfigWebApplicationContext> {

    @Override
    public void initialize(AnnotationConfigWebApplicationContext applicationContext) {
        // add module config to enviroment property sources
        MyMagnoliaModule module = Components.getComponent(MyMagnoliaModule.class);
        MyPropertySource myPropertySource =
                new MyPropertySource("myModuleConfig", module.getModuleConfiguration());
        MutablePropertySources sources = applicationContext.getEnvironment().getPropertySources();
        sources.addFirst(myPropertySource);
    }
}

Problems to solve:

  • Automatic context refresh after module configuration updates
  • Better ApplicationContextInitializer Support for Blossom (BLOSSOM-229)


 Comments   
Comment by Tobias Mattsson [ 04/Mar/16 ]

When you've made changes to the config of your module Magnolia will restart it. You'll get callbacks to your module instance allowing you to take down the servlets and application context and then start new instances. This is essentially what a refresh would do. If you have this in your module class then remove it and you'll get this behavior:

if (moduleLifecycleContext.getPhase() == ModuleLifecycleContext.PHASE_SYSTEM_STARTUP) {

Since you've tagged this with blossom-spring-loaded I'm assuming you're using this during development. In production you probably don't want to use this since a restart of the dispatcher servlet will break concurrent rendering until it has initialized again. If what you're looking for is a property source that you can configure and manage in JCR and have it take immediate effect there's other ways to do that. I'm thinking of a PropertySource implementation that uses JCR observation to monitor a node hierarchy and base its properties on it. It could also dispatch an event within the application context and servlets when properties have changed so that beans within them can adapt. This would be useable in production without disrupting concurrent rendering.

Comment by Tobias Mattsson [ 01/Apr/16 ]

Was this helpful at all?

Generated at Sun Feb 11 23:31:26 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.