Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Magnolia with Blossom and Spring-Loaded

DZone's Guide to

Magnolia with Blossom and Spring-Loaded

· Performance Zone ·
Free Resource

Container Monitoring and Management eBook: Read about the new realities of containerization.

It is quite easy to use spring loaded with magnolia-blossom. We just refresh the appCtx when reloading a Template or Area, and fire a BlossomDispatcherInitializedEvent to re-export the Template-definitions. Happy Reloading.

package de.eiswind.magnolia.springloaded;
 
import info.magnolia.module.blossom.annotation.Area;
import info.magnolia.module.blossom.annotation.Template;
import info.magnolia.module.blossom.dispatcher.BlossomDispatcherInitializedEvent;
import info.magnolia.module.blossom.render.BlossomDispatcherServlet;
import org.springframework.context.ConfigurableApplicationContext;
import org.springsource.loaded.Plugins;
import org.springsource.loaded.ReloadEventProcessorPlugin;
 
/**
 * Created by thomas on 18.04.15.
 */
public class BlossomReloadPlugin implements ReloadEventProcessorPlugin {
 
 
 
    private BlossomDispatcherServlet dispatcherServlet;
 
    public BlossomReloadPlugin(BlossomDispatcherServlet servlet){
 
        this.dispatcherServlet = servlet;
        Plugins.registerGlobalPlugin(this);
 
    }
 
    @Override
    public boolean shouldRerunStaticInitializer(String s, Class<?> aClass, String s1) {
        return false;
    }
 
    @Override
    public void reloadEvent(String s, Class<?> aClass, String s1) {
        Template templateAnnotation = aClass.getAnnotation(Template.class);
        Area areaAnnotation = aClass.getAnnotation(Area.class);
        if (templateAnnotation == null && areaAnnotation == null) {
            return;
        }
        ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) dispatcherServlet.getWebApplicationContext();
        applicationContext.refresh();
       applicationContext.publishEvent( new BlossomDispatcherInitializedEvent(dispatcherServlet));
    }
}
 
// add this in your blossom-module start
...
super.initBlossomDispatcherServlet("blossom", BlossomServletConfiguration.class);
new BlossomReloadPlugin((BlossomDispatcherServlet)getDispatcherServlets().get(0));
...
 
// launch magnolia with spring loaded agent
-javaagent:/{{your_dir}}/springloaded-1.2.3.RELEASE.jar -noverify




Take the Chaos Out of Container Monitoring. View the webcast on-demand!

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}