Deploying a Spring MVC Portlet

Developers creating portlets for Liferay DXP can usually deploy their portlet as Java EE-style Web Application ARchive (WAR) artifacts or as Java ARchive (JAR) OSGi bundle artifacts. Spring MVC portlet developers don’t have that flexibility. Spring MVC portlets must be packaged as WAR artifacts because the Spring MVC framework is designed for Java EE. Therefore, it expects a WAR layout and requires Java EE resources such as the WEB-INF/web.xml descriptor.

Because Liferay supports the OSGi WAB (Web Application Bundler) standard for deployment, you can deploy your WAR and it runs as expected in the OSGi runtime. Here are the high points on why that works in Liferay:

  • The Liferay auto-deploy process runs, adding the PortletServlet and PlugincontextListener configurations to the WEB-INF/web.xml file.

  • The Liferay WAB Generator automatically creates an OSGi-ready META-INF/MANIFEST.MF file. If you want to affect the content of the manifest file, you can place bnd directives and OSGi headers directly into a WEB-INF/liferay-plugin-package.properties file for the WAB.

Import class packages your portlet’s descriptor files reference by adding the packages to an Import-Package header in your liferay-plugin-package.properties file.

Here’s an example Import-Package header:

Import-Package:\
    org.springframework.beans.factory.xml,\
    org.springframework.context.config,\
    org.springframework.security.config,\
    org.springframework.web.servlet.config

The auto-deploy process and Liferay’s WAB generator convert your project to a Liferay-ready WAB. The WAB generator detects your class’s import statements and adds all external packages to the WAB’s Import-Package header. The generator merges packages from your plugin’s liferay-plugin-package.properties into the header also.

If you depend on a package from Java’s rt.jar other than a java.* package, override portal property org.osgi.framework.bootdelegation and add it to the property’s list. Go here for details.

Once you’ve packaged your Spring MVC portlet as a WAR, you can deploy it by copying it to [LIFERAY_HOME]/deploy.

Congratulations on deploying your Spring MVC portlet!

« Configuring a Spring MVC PortletJSF Portlets with Liferay Faces »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 1