Skip to content

Instantly share code, notes, and snippets.

@eiswind
Last active August 29, 2015 14:19
Show Gist options
  • Save eiswind/da03739cb9c0672132aa to your computer and use it in GitHub Desktop.
Save eiswind/da03739cb9c0672132aa to your computer and use it in GitHub Desktop.
spring-loaded magnolia blossom plugin
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment