我正在使用Spring,Hibernate和JSF.
为了从应用程序上下文中获取bean,我写道:
public static Object findBean(String name) {
return FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean(name);
}
Run Code Online (Sandbox Code Playgroud)
但是,FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance())返回null,因此调用getBean()它会抛出NullPointerException
我需要在任何地方定义任何东西吗?
EDITED
我需要从应用程序上下文而不是jsf bean获取bean