Liferay Service-Builder mechanism generates a lot of code, it’s very easy to use and it lets you use the Liferay Service API.

If you want to use external classes in your service impl classes you must use a special annotation : @BeanReference (from the package com.liferay.portal.kernel.bean)

Using this annotation you can inject your classes into your service and then use it without having any exceptions on class loading context.

Steps

  1. Declare the bean you want to inject in the spring configuration file of your portlet
  2. <bean id="com.test.service.MyService" class="com.test.service.impl.MyServiceImpl" />
  3. Make a reference to this bean in your service impl class
  4. @BeanReference(type = MyService.class)
    private MyService myService;

Et voila! Now you can use the service “myService” in your service impl methods :)

NB : if you want to understand how the injection is done, have a look at this class : BeanReferenceAnnotationBeanPostProcessor