I am using Spring, Hibernate and JSF.
In order to get a bean from application context I write:
public static Object findBean(String name) {
return FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean(name);
}
However, the FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()) returns null, so calling getBean() on it throws NullPointerException
Do I need to define anything anywhere?
EDITED
I need to get the bean from application context and not jsf bean
FacesContext.getCurrentInstance()returnsnullif your are not within a request that is handled by theFacesServlet. Make sure you are handling a request passed through that servlet.Update: If the faces context is not null, the reason why the application context may be null is that there is no servlet context attribute named
org.springframework.web.context.WebApplicationContext.ROOT. This means spring is not initialized properly. Make sure you have either the springContextLoaderListenermapped inweb.xml, or theDispatcherServlet