Search code examples
javaspringportletliferay-6

Java spring portlet extends GenericPortlet how to autowire dependencies


I am using java - spring - portlet

I want to keep using my portlet as extend to GenericPortlet but i want to use spring dependency injections.

Currently i found the work around which is as follows instead i want to autoWire AccountsDao dependency. Can somebody help me out that how can i autowire when my portlet extends GenericPortlet and not @Controller

public class HelloPortlet extends GenericPortlet {

@ProcessAction(name = "searchAccount") 
    public void listAllAccounts(ActionRequest request, ActionResponse response) {

ApplicationContext springCtx = PortletApplicationContextUtils
                .getWebApplicationContext(getPortletContext());
        AccountsDao dao  = (AccountsDao)springCtx.getBean("accountsDao");
}

}

Solution

  • Finally I had to configure and enable spring based controllers to acheive this instead of extending to GenericPortlet...