title: How to inject ApplicationContext in JAX-RS
body: <p>I am writing a web service using Spring and JAX-RS, and I'm kinda confused with the following</p>
  
  <p>Here's my service exmaple</p>
  
  <pre><code>@Path("/users")
  public class UserService {
  
      @GET
      @Path("{id}")
      @Produces("application/xml")
      public User getById(@PathParam("id") int id) {
          ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
          UserDAO userDAO = (UserDAO) context.getBean("userDao");
          return userDAO.getById(id);
      }
  
  }
  </code></pre>
  
  <p>And here's my beans.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://www.springframework.org/schema/beans"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
  
      &lt;!-- Initialization for data source --&gt;
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/hospital-system"/&gt;
          &lt;property name="username" value="root"/&gt;
          &lt;property name="password" value="root"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="userDao" class="dao.UserDAO"&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>I wonder if this is the right technique to load Application context each time the resource get's called, and if no, how should I change it? </p>