Spring Libraries Plugin - Documentation topics on: osgi,spring,spring controller,.

Spring Libraries Plugin

This bundle plugin is an example of how to add Spring support to a bundle plugin, creates and registers a simple Spring Controller using a different Spring version that the one shipped with dotCMS in order to extend the reach of this example.

How to create a bundle plugin with Spring support

Let’s review the file organization on the Spring (com.dotcms.spring) example.

META-INF/MANIFEST.MF: The manifest file is very important for the deployment, it lists the Bundle Name, Version and Packages.

In this MANIFEST you must specify (see template plugin):

  • Bundle-Name: The name of your bundle
  • Bundle-SymbolicName: A short an unique name for the bundle
  • Bundle-Activator: Package and name of your Activator class (example: com.dotmarketing.osgi.custom.spring.Activator)
  • Bundle-ClassPath: The Bundle-ClassPath specifies where to load classes and jars from from the bundle. This is a comma separated list of elements to load (such as current folder,lib.jar,other.jar). (Example: ., lib/com.springsource.org.aopalliance-1.0.0.jar)
  • DynamicImport-Package: * Dynamically adds required imports the plugin may need without adding them explicitly.
  • Import-Package: This is a comma separated list of package's name. List the packages that you are using inside the bundle plugin and that are exported by dotCMS.


In order to work inside the Apache Felix OSGI runtime, the import and export directive must be bidirectional.

In dotCMS you must declare the set of packages that will be available to the OSGI plugins by changing the file: dotCMS/WEB-INF/felix/osgi-extra.conf.
This is possible also using the dotCMS UI (System -> Dynamic Plugins -> Exported Packages).

Only after that exported packages are defined in this list, a plugin can Import the packages to use them inside the OSGI blundle.


Under the src folder you will find all the Java classes needed to create a new Spring Controller:

$ pwd  
$ ls -l  
-rw-r--r-- 1 Activator.java  
-rw-r--r-- 1 ExampleController.java  
-rw-r--r-- 1 CustomViewResolver.java  
-rw-r--r-- 1 CustomView.java


Simple annotated Spring Controller. Controller annotates @ /examplecontroller

@RequestMapping (“/examplecontroller”)

For more information on how dotCMS supports Spring MVC please visit this blog.


Custom implementation of an Spring ViewResolver.


Custom implementation of an Spring View.


Standard Spring configuration file to enable the support for annotation-driven controllers and the Spring component-scan functionality.

Maps the controller to com.dotmarketing.osgi.custom.spring.ExampleController and the view on paths: /application/spring/*.html

In our example, the controller returns helloworld, mapping the view to the dotCMS HTMLPage /application/spring/helloworld.html


This bundle activator extends from com.dotmarketing.osgi.GenericBundleActivator and implements BundleActivator.start().

Manually registers the class DispatcherServlet to our spring configuration file (example-servlet.xml).

* PLEASE note the “publishBundleServices( context )” call, this call is MANDATORY (!) as it will allow us to share resources between the bundle, the host container (dotCMS) and the Spring context.


The Spring controller is registered under the url pattern “/spring” can be test it running and assuming your dotcms url is localhost:8080: