Friday, August 28, 2015

JRebel plugin for Magnolia Blossom

Blossom user Arne Diekmann has created a JRebel plugin for development with Blossom and Magnolia. The source along with usage instructions is available on their project page at Bitbucket.

It is a port of the plugin for Spring Loaded I released back in May.

I'm still not sure how to use the Spring Loaded plugin with Eclipse, although I am convinced that it's possible, so for those of you using Eclipse this plugin should come in handy.

Friday, May 29, 2015

Develop faster with the Blossom plugin for Spring Loaded

Spring Loaded is an open source JVM agent that improves on the JVMs hot-code replace functionality. It does for instance make it possible to add, remove and rename methods and add annotations or change their values. Using it while developing means you can avoid restarting the application and save a lot of time.

Since Blossom makes heavy use of annotations Spring Loaded can be a real time saver.

Spring Loaded has basic support for Spring built-in but it's not enough to cover what we need for Blossom. To find templates, dialogs, etc, Blossom scans the beans available and introspects their classes to find the information it needs in their annotations. This needs to be done again every time Spring Loaded reloads a class. For this we need a custom plugin.

The Spring Loaded plugin for Blossom version 1.0 was released today and is available in the Magnolia CMS maven repository.

When added to your project it will automatically find all BlossomDispatcherServlets and refresh their ApplicationContexts. Refreshing an ApplicationContext makes it dispose of all beans its currently managing and creating new ones. It's a pretty costly operation but it's what's needed to make Blossom see the changes. Most applications have their main infrastructure beans that takes time to start in the root web application context and only simpler beans in DispatcherServlets so this should be fine.

It will by default only refresh if it sees a class reloaded that has a Blossom annotation or the @Controller annotation. This can be changed so it refreshes on any change by setting the BlossomSpringLoadedPlugin.refreshOnAnyChange system property to true.


If you have standard DispatcherServlets in your projects it can be useful to have those refreshed as well. If you set the BlossomSpringLoadedPlugin.refreshAllDispatcherServlets system property to true the plugin will refresh those too.


To use the plugin start by downloading the Spring Loaded JAR. Then add it to the JVM using these JVM arguments:

-javaagent:<path to the JAR> -noverify

Then add the plugin dependency to your project.


After this you can start the application in debug mode and reload changes using hot-swap. But since Magnolia projects are multi module maven projects its unfortunately not this easy. Spring Loaded 1.2.3 doesn't reload classes from JAR files. It's been said this is coming in the next release, 1.2.4.

Until 1.2.4 is out you need to reconfigure your development environment to place classes inside WEB-INF/classes instead of inside JAR files in WEB-INF/lib.

I don't know how to do it in Eclipse but I suspect its possible to configure in project properties in the Build Path and Deployment Assembly views. Please leave a comment if you know how to do this.

In IntelliJ you open Project Structure, select Artifacts, click on your artifact (the one that ends in war exploded), then on the Output Layout tab you expand WEB-INF/lib and remove your module. Then scroll back up and add it to WEB-INF/classes.

If you later do reimport of your maven projects in IDEA you'll need to do this again because IDEA will restore the settings.

Hopefully, this should save you a bunch of time!

A huge credit to Thomas Kratz who shared his work on using Magnolia with Blossom and Spring Loaded on his blog and for his ideas on how to improve it!

Thomas also wrote a module for using Thymeleaf with Blossom, great work!

Tuesday, May 5, 2015

Blossom at Spring I/O 2015

Last week the Spring I/O conference was held in Barcelona, Spain. There were sessions covering most of the Spring landscape ranging from WebSocket and Server Sent Events support in MVC to Spring Cloud and Spring XD.

The conference opened with Juergen Hoeller's keynote where he took us back to the inception of Spring Framework and then shared anecdotes and stories through the years up to where we are now and with the Spring team at Pivotal.

I had the pleasure to give a talk on Blossom about how Blossom brings Spring into Magnolia CMS.

It's been eight years since I went to a Spring conference in Europe, the last one was SpringOne 2007 in Antwerp. Europe has been lacking a good Spring conference for years and in my opinion we now have a great one in Spring I/O. Go there in 2016!

Below are the slides from my talk: