无法从portlet调用spring bean

时间:2012-08-16 05:41:21

标签: spring liferay liferay-6 spring-jdbc

我有如下的Spring bean:

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

我有一个portlet尝试访问它,如下所示:

   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)

如果我遗漏某些东西,请告诉我 来源可用@http://portletsinaction.googlecode.com/svn/trunk/ch9_BookCatalogSpringJdbc/

enter code here

1 个答案:

答案 0 :(得分:0)

Liferay 6.1.1的问题 我已经用6.0.6进行了测试,并且工作正常。