Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
suman daida
Failing to call spring bean from portlet
August 16, 2012 5:38 AM
Answer

suman daida

Rank: New Member

Posts: 7

Join Date: August 8, 2012

Recent Posts

I have Spring bean as below:

@Service("bookService")
public class BookServiceImpl implements BookService {
@Autowired
@Qualifier("bookDao")
private BookDao bookDao;

i have a portlet trying access it as below:

62 public BookService getBookService() {
63 ApplicationContext springCtx = PortletApplicationContextUtils.getWebApplicationContext(getPortletContext());
64 return (BookService)springCtx.getBean("bookService");
}


but i have the below nullpointer exception:
java.lang.NullPointerException
at chapter09.code.listing.base.BookCatalogPortlet.getBookService(BookCatalogPortlet.java:64)
at chapter09.code.listing.base.BookCatalogPortlet.init(BookCatalogPortlet.java:59)

Please let me know if i am missing some thing

source available @http://portletsinaction.googlecode.com/svn/trunk/ch9_BookCatalogSpringJdbc/


I have also tried with
WebApplicationContext springCtx = (WebApplicationContext)PortletApplicationContextUtils.getRequiredWebApplicationContext(getPortletContext());
and i have :
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?

I have below listner in web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

using liferay 6.1
Andrius Kurtinaitis
RE: Failing to call spring bean from portlet
August 23, 2012 2:35 AM
Answer

Andrius Kurtinaitis

Rank: Junior Member

Posts: 62

Join Date: January 24, 2010

Recent Posts

I also have a similar problem. I believe it happens starting with Liferay 6.1 GA2, because the previous versions did not have this problem. I got not solution yet.
suman daida
RE: Failing to call spring bean from portlet
August 23, 2012 3:27 AM
Answer

suman daida

Rank: New Member

Posts: 7

Join Date: August 8, 2012

Recent Posts

Yes, its liferay version problem.

I tried with 6.0.6 and its working fine
Durrab Khan
RE: Failing to call spring bean from portlet
August 30, 2012 2:47 AM
Answer

Durrab Khan

Rank: New Member

Posts: 13

Join Date: May 11, 2012

Recent Posts

Any body solved that issue.

I am also facing the same issue

No WebApplicationContext found: no ContextLoaderListener coming in my xhtml and I did the same

I have added the Spring RequestListener and did some configuration in faces-config.xml
Andrius Kurtinaitis
RE: Failing to call spring bean from portlet
August 30, 2012 3:05 AM
Answer

Andrius Kurtinaitis

Rank: Junior Member

Posts: 62

Join Date: January 24, 2010

Recent Posts

The bug is said to be fixed here: http://issues.liferay.com/browse/LPS-29103.
After applying the fix in some portlets accessing PortletProps during Spring context initialization i got another problem similar to http://issues.liferay.com/browse/LPS-28805.
I worked around it by accessing portlet.properties at some later time.