2

I am developing a service hook for Liferay, and I want to use an external EJB to do the business logic for me. Is there any way to inject a bean to a service class?

Here is my code:

public class MyUserService extends UserServiceWrapper {

    //I want a bean injected
    @Inject
    MyBean myBean;

    public MyUserService(UserService userService) {
        super(userService);
    }

    @Override
    public User addUserWithWorkflow(/* all kind of parameters */)
            throws PortalException, SystemException {
        User user = super.addUserWithWorkflow(/* all parameters passes here //);

        //do my business logic here
        myBean.userRegistered(user);

        return user;
    }
}

Is there any way to do this?

palacsint
  • 28,416
  • 10
  • 82
  • 109
Abel
  • 21
  • 2

1 Answers1

0

If the bean is already loaded in the AppContext (use a hook-spring.xml file) you can use

Object bean = com.liferay.portal.kernel.bean.PortletBeanLocatorUtil.locate(
       "bean id", "class")

Is that what you were looking for?

Dave W
  • 21
  • 2