If we are using spring and JSF auto-wiring spring class into JSF managed bean is very easy by using @Autowired or @ManagedProperty. Now if we want to inject JSF managed bean into HTTP Servlet How can we do this?

Since Servlet and JSF are different container and JSF works on top of Servlet container. We will not be able straight forward inject it.Since all these beans are under sessions, We can use below approach to get Managed bean instance into Servlet

public class HelloServlet extends HttpServlet {

protected void doGet(HttpServletRequest request,

   HttpServletResponse response) throws ServletException, IOException {

  CustomerBean beanObj =(CustomerBean ) req.getSession().getAttribute("customerBean");

 }

}


Managed bean defined as below

@ManagedBean(name="customerBean")

@SessionScoped

public class CustomerBean  implement Serializable

{
}