« Back to Extension...

Business Logic Customization Example

Table of Contents [-]

    So you love everything about a built in Liferay function except for one thing, what should you do? Customize it of course! But how does one change the business logic in a Liferay Impl class without changing the code? This is what this document will show you.

    Let's take adding a new User for example. By default, you are required to enter a screen name, valid email address, first name, and last name. Let's try to change the business logic so that screen name is NOT required.

    The Action Class / method controlling the form submit is EditUserAction.updateUser(). Somewhere in there UserServiceUtil.addUser() is called, and we know that Liferay Util classes are autogenerated via Service Builder. The business logic lies within UserLocalServiceImpl.addUser().


    1. Create a new class that extends UserLocalServiceImpl.java and include the methods you want to override. Place this class in your ext environment. For example:

      package com.ext.portal.service.impl;
      public class ExtUserLocalServiceImpl extends UserLocalServiceImpl {
         public User addUser(
         protected void validate(

    2. Modify spring configuration file to tell the Util to talk to the Impl. An easy way to do this is to search for "UserLocalServiceImpl" in portal-spring.xml. You will see this:

     <bean id="com.liferay.portal.service.UserLocalService.professional" class="com.liferay.portal.service.impl.UserLocalServiceImpl" lazy-init="true" />

    We don't to touch portal-spring.xml or ext-spring.xml because their contents are autogenerated. So we'll create a new spring configuration file called custom-spring-info.xml and place it in ext-impl/classes/META-INF/. Input your new Impl reference:

     <bean id="com.liferay.portal.service.UserLocalService.professional" class="com.ext.portal.service.impl.ExtUserLocalServiceImpl" lazy-init="true" />

    Note: for some reason the name custom-spring.xml does not work. custom-spring-info.xml does work.

    3. Modify portal-ext.properties to read your new spring configuration file:


    4. Deploy your changes to tomcat and your good to go. Place a debug point in your custom class to make sure it's getting read.

    0 Attachments
    Average (0 Votes)
    The average rating is 0.0 stars out of 5.
    Threaded Replies Author Date
    Thank you for this sample! One minor thing:... Hubert Felber January 28, 2010 6:42 AM
    Is this still the way to do it for v5.2.3? Pablo Krause February 26, 2010 12:48 PM
    Hello all, I followed the above article step... Heba El Ayoty January 24, 2011 1:01 AM
    Hey, did you solve it in Liferay 6.0.5? Viktor Palai March 25, 2011 4:56 AM

    Thank you for this sample!
    One minor thing: custom-spring-info.xml should go to src\META-INF not classes\META-INF. Otherwise "ant clean" will remove it.
    Posted on 1/28/10 6:42 AM.
    Is this still the way to do it for v5.2.3?
    Posted on 2/26/10 12:48 PM in reply to Hubert Felber.
    Hello all,
    I followed the above article step by step in Liferay 6.0.5 Enterprise edition, but it doesn't work with me....
    no errors but it seems like liferay doesn't feel that anything new is happened emoticon
    Posted on 1/24/11 1:01 AM.

    did you solve it in Liferay 6.0.5?
    Posted on 3/25/11 4:56 AM in reply to Heba El Ayoty.