Liferay - Override ServiceImpl Using Ext

1 comment
It is recommended to implement hook to override any portal service but there are certain limitation if you are overriding portal service using hook.

Override a Portal Service using Hook

You won't be able to access any class of portal-impl.jar inside hook so its better to use ext-plugin in such case.

This post will describe how to override any service impl class using ext.

First of all create ext-plugin. Inside ext-impl/src create META-INF folder.

Create ext-spring.xml file. You might have question why we have to create xml file with this specific name. To know more on this you need to check spring.configs property of portal.properties file.







Check at the bottom of this property. You will see ext-spring.xml so Liferay will look for this xml to override any class injected through spring.

If you don't want to override default  ext-spring.xml then for your custom spring configuration you can copy spring.configs property from portal.properties file and paste it inside portal-ext.properties.
Append name of your custom-spring.xml at the end of this property.


To override method of MBMessageLocalServiceImpl add following entry inside ext-spring.xml.

<bean id="com.liferay.portlet.messageboards.service.MBMessageLocalService" class="com.custom.portlet.messageboards.service.impl.CustomMBMessageLocalServiceImpl" />

You can get bean defination from spring configuration files mentioned in spring.configs property.
For MBMessageLocalServiceImpl bean details are available inside portal-spring.xml file.

Similar way to override PortalLDAPImporterUtil you need look into ldap-spring.xml for bean defination.

Now next thing is to create CustomMBMessageLocalServiceImpl which must extend MBMessageLocalServiceImpl .

public class CustomMBMessageLocalServiceImpl extends MBMessageLocalServiceImpl

Now you can override any method of MBMessageLocalServiceImpl inside CustomMBMessageLocalServiceImpl .


You only need to write specific method you want to override. No need to copy entire code of original class.


Next PostNewer Post Previous PostOlder Post Home

1 comment: