我正在使用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