Liferay MVC vs Spring MVC is an interested topic. Both are widely used portlet frameworks to create portlet in Liferay portal.
Liferay MVC vs Spring MVC is one of the most hot topic for liferay developer. It always creates confusion as what to choose when. In this article I will be showing comparison between these two frameworks to create portlet in Liferay
Liferay MVC vs Spring MVC
It is easy to understand the differences and similarities between Liferay MVC vs Spring MVC by comparing their characteristic side by side.
- Spring MVC is full-fledged architecture to build robust, flexible and loosely coupled web application. Spring MVC Portlet is a part of Spring Web MVC framework provide by Spring.
- Liferay MVC on other hand is light weight framework to build portlets for Liferay portal only.
- MVCPortlet (or it’s sub class) is a portlet class for Liferay MVC.
- DispatcherPortlet is working as portlet class for Spring MVC. DispatcherPortlet is a main front controller which dispatch the request to individual handlers.
- Liferay MVC can have just one render method. However liferay provides mechanism to render different jsps at runtime. render URL is used to call render method.
- Spring MVC portlet provides multiple render methods. There will be one default render method which is called by default. To call other render methods, you need to pass render method mapping key to action parameter while creating render URL.
- Both Liferay MVC and Spring MVC frameworks supports multiple action methods.
- In Liferay MVC, you can define just one resource method.
- In Spring MVC, you can define multiple resource method.
- Liferay MVC framework is provided by liferay. All underlying classes are available only in Liferay portlet. Because of this reason, you can’t deploy Liferay MVC portlet on other portal.
- Spring MVC has no dependency on any portal. You can deploy Spring MVC Portlet on any other portals.
Liferay IDE Support
- Liferay MVC is inbuild portlet framework provided by Liferay. It’s supported by Liferay IDE. You can create Liferay MVC Portlet in Liferay IDE or Liferay Developer Studio.
- Liferay IDE currently does not supports creating Spring MVC Porltet out of the box. However you can follow steps to create Spring MVC Portlet in Liferay IDE
- Liferay MVC provides JSP to show your content in very simple way. The view path mapping is written in portlet.xml file.
- In Spring MVC portlet, you can plug many view technologies like JSP, Freemarker, Velocity, PDF etc. Spring provides view resolvers to generate output in different format for each of these view technologies. The mapping is written in sprint context file.
- Liferay MVC is out of the box not provides any direct spring integration.
- Spring MVC portlet framework on other hands inherits all the features of Spring MVC (Web) so it provides spring integration by default.
- Liferay MVC just inherits classes that are provided by Liferay and there is no other dependencies. It uses comparatively less memory than Spring MVC portlet. But again the memory consumption depends on actual portlet code. But if you compare the plain portlet(without any business login), Liferay MVC wins here.
What to use Liferay MVC vs Spring MVC and When
- The simple answer is – it depends
- LiferayMVC is a light weightportlet framework. It provides basic skeletons to create portlet in Liferay. It can be used when you want your portlet to do simple task that requires just one or two actions methods and comparatively small amount of render logic.
- On the other hand, Spring MVC portlet is full featured portlet mvc framework. It provides many functionality that are inherited from its counter part Spring web MVC. You may develop your portlet in Spring MVC when
- Your portlet suppose to do many tasks.
- You need multiple render / resource methods
- Spring MVC support multiple render and resource method.
- Instead of writing if-else condition in single render / resource method you can write multiple render / resource methods in Spring MVC Portlet.
- Liferay MVC and Spring MVC are vastly used portlet framework to create portlets in Liferay.
- Liferay MVC is a lightweight framework which can be used to create portlet if it contains less complex render / resource logic and few action methods.
- On other hand Spring MVC is full fledged portlet framework. It provides many functionality.
- You can use Liferay MVC for simple portlet creation. Spring MVC Portlet framework can be used where you have complex render / resource logic and you need spring integration in your portlet.
- Liferay MVC vs Spring MVC is always debatable topic. You should choose the appropriate framework while created portlet based on you requirement
- You may refer this link to create portlet in Liferay