我正在使用Spring,Hibernate和JSF。FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance())返回null
为了得到从应用程序上下文的bean我写:
public static Object findBean(String name) {
return FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean(name);
}
然而,FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance())
返回NULL,所以调用getBean()
它抛出NullPointerException
我需要的任何地方定义什么?
EDITED
我需要的,如果你的是不是由FacesServlet
处理的要求内得到应用上下文的bean,而不是JSF豆
什么是确切的引用'null`?那些是静态方法,它们不可能抛出NPE。你不是说`FacesContext#getCurrentInstance()`返回null,而且NPE实际上是在`getWebApplicationContext()`方法中抛出的吗? – BalusC 2011-01-24 19:32:25
FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance())返回null。 FacesContext.getCurrentInstance()不为null! – Dejell 2011-01-24 19:38:05