Latest Posts

Archives [+]

Spring + Sling = Spling

One of the aspects in CMS projects that routinely pops up is the integration of the CMS-based application with some other web application. For example, consider a CMS-based brochure-style web site and an e-banking application. Typically, these are implemented in different systems, but shall be presented to the user in a unified fashion.

Many of Day's customers have a large investment in Spring-based applications which comes as no surprise as Spring is certainly the 800 pounds gorilla in the Java frameworks space these days. Thus, Day developer Alex Klimetschek and I met with Sandro Ruch and Jan Stettler of Day partner company Namics to discuss ways to integrate Communique 5 and Spring-based applications. Sandro and Jan look back to years of experience in Communique and Spring and delivered a large number of projects based on each of them.

The results of this workshop to combine CQ5/Sling-based and Spring-based applications were slightly surprising: it is just so easy. Due to the standards-based approach of Sling the integration boils down to two very simple scenarios:

Spring application in Sling

In this scenario a Spring-based application shall be used from within a Sling-based application. A typical use case would be the integration of legacy data.

The solution for this use case is based on Spring's Dynamic Modules. Dynamic Modules enable Spring application to be deployed in an OSGi container. Since Sling runs on OSGi the Spring application can be deployed into Sling and is afterwards available as an OSGi service. The service's exposed classes and methods are accessible from the Sling view's as any other service.

This integration approach allows Spring developers to develop and test application components that have no dependencies on the content management system. The OSGi-based deployment approach further decouples development cycles of the web developer and the Spring developer.

I intend to write up a little tutorial on deploying Spring apps into Sling (but if you do not want to wait give it a try, it is really easy). A post on deploying regular OSGi beans (without Spring) in Sling is already available.

Access to content from Spring application

The integration approach above is most suitable for "headless" Spring apps, i.e. for applications that consist solely of business logic and do not contain a web tier. If the Spring application is a complete web application the typical integration problem is how to access CMS-managed content from the Spring beans.

Of course, CQ5 is JCR-compliant so the content can be accessed through standard JCR connections (there is also a Spring JcrTemplate available). However, with Sling things get even simpler: the CMS can get accessed through the REST. All nodes and trees are already available in JSON and plain text format and XML will soon follow. So integrating the content really just involves sending HTTP requests. This approach will carry you very far without having to resort to JCR connections (but it surely feels comforting that this lower level access is always there).

You might have noticed it already: REST-based content integration is not confined to Spring or even Java. Sling opens up JCR-based content to any system that speaks HTTP (see also the discussion here).

Next week, I will post on integrating Sling, Spring and Swing to Splwing... Just kidding.

 

COMMENTS

  • By Michael Marth - 11:41 AM on May 25, 2008   Reply
    Sandro also <a href="http://blog.namics.com/2008/05/spling_auf_den.html">posted on this workshop</a><br/>
  • By - 5:13 PM on Sep 12, 2009   Reply
    Good doc. <br/>Do you have detail somewhere for integrating Sling and Spring DM Web. <br/><br/>Thanks<br/>
  • By Gary Gilchrist - 4:10 PM on Jan 02, 2011   Reply
    I'm doing some research into how we can use our existing Spring based Services deployed as packages and accessible via Sling. Our services rely on Spring Security and in several instances we use "autowiring" of an Interface implementation. From what I can tell so far Spring DM is the only possible route (as opposed to simply using the Spring jars). As I am just getting started, I would certainly be interested in what advice you might have deploying Spring based services into Sling and in particular any details on what ought to be done regarding OSGi bundles used for the POJOs of my Spring based Service Impl (even if it is easy ;)