FacesContextUtils.getWebApplicationContext (FacesContext.getCurrentInstance ()) returns null

I use Spring, Hibernate and JSF.

To get a bean from the application context, I write:

public static Object findBean(String name) {
  return FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean(name);
 }

However, it FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance())returns null, so calling getBean()on it callsNullPointerException

Does anything need to be defined somewhere?

EDITED

I need to get bean from application context, not jsf bean

+2
source share
1 answer

FacesContext.getCurrentInstance()returns nullif you are not in the request being processed FacesServlet. Make sure that you are processing the request submitted through this servlet.

: , , , org.springframework.web.context.WebApplicationContext.ROOT. , spring . , spring ContextLoaderListener, web.xml, DispatcherServlet

+6

All Articles