Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package br.com.jreader.util; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.ServletContext; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; /** * * @author Jonathan */ public class ServiceFinder { public static Object findBean(String beanName) { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); ServletContext servletContext = (ServletContext) externalContext.getContext(); ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); Object object = applicationContext.getBean(beanName); return object; } }