title: How to use @Resource annotation in servlet (or in any other Java class)?
body: <p>I am experimenting with Java Dependency Injection. Many questions here on SO talk about jndi resources being wired. But I think, a java class can be wired using <code>@Resource</code> annotation. I have a simple servlet in which I have two properties to be wired using CDI. I am using Tomcat6, Servlet 2.5, and Weld configuration. </p>
  
  <p><strong>The servlet code:</strong></p>
  
  <pre><code>@Inject
  private HikariConnectionProperties hikariConnectionProperties;
  
  @Resource(name = "connectionProvider")
  private IConnectionProvider connectionProvider;
  </code></pre>
  
  <p>However I get the code compiled, deployed. But, when there is a request for the corresponding servlet I get <code>javax.naming.NameNotFoundException: Name connectionProvider is not bound in this Context</code>.</p>
  
  <p>But, I have <code>@Named</code> annotation for the <code>ConnectionProvider</code> class. <strong>The same configuration works with <code>@Inject</code> for both the fields.</strong></p>
  
  <p>So, my first question is how can I fix this issue? And is there any way that I can specify scope for a particular injection(using only annotations of JSR) without using Spring's <code>@Scope</code>? Any example is a great help as I am a newbie to CDI.</p>