title: Access Business Object in a servlet inside JSF / Spring application?
body: <p>Usually, i'm accessing business objects (services) with @ManagedProperty in a main class annotated with @ManagedBean.</p>
  
  <p>Here, i have a Servlet and i want to inject my business objects.
  The use of managedProperty doesn't work with the annotation @WebServlet.</p>
  
  <p>When i use WebApplicationContext, it's working.</p>
  
  <p>Does the use of WebApplicationContext is the clean way to do that or is there a cleaner method to do it ?</p>
  
  <pre><code>@WebServlet(urlPatterns ="/Graphic")
  public class GraphicServlet extends HttpServlet {
  
      // Method 1 - This is not working ( the usual way in a ManagedBean)
      @ManagedProperty(value="#{participantBo}")
      private ParticipantBo participantBo; // getters and setters added
  
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
          // Method 2 - This is working
          WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
          ParticipantBo participantBo = (ParticipantBo) springContext.getBean("participantBo");
  
          List&lt;Participant&gt; myParticipants = participantBo.findAllParticipant();
  
          for (Participant participant : myParticipants) {
              System.out.println(participant.getId_study());
          }
      }
  }
  </code></pre>