title: @Named annotation can't load a bean in a Servlet - javax.naming.NameNotFoundException: Name student is not bound in this Context
body: <p>I originally used @Component for a bean(Student.java) that is being called in a Servlet. I changed @Component to @Named. I used to use following code to get the student bean in the Servlet.</p>
  
  <pre><code>Student student = (Student)applicationContext.getBean("student")
  </code></pre>
  
  <p>After I changed to @Named, the bean is no longer being detected. I am getting following error messages. Could anyone tell me what is the problem? I placed javax.inject-1.jar file under webapps\student-enrollment\WEB-INF\lib\</p>
  
  <pre><code>Context init...
  Logger name for context: student-enrollment
  Context logger config file: logback-student-enrollment.xml
  Adding logger context: student-enrollment to map for context: student-enrollment
  2014-09-10 20:46:19.361 Servlet /student-enrollment threw load() exception
  javax.naming.NameNotFoundException: Name student is not bound in this Context
          at org.apache.naming.NamingContext.lookup(NamingContext.java:770) ~[catalina-6.0.36.jar:6.0.36]
          at org.apache.naming.NamingContext.lookup(NamingContext.java:153) ~[catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.util.DefaultAnnotationProcessor.lookupFieldResource(DefaultAnnotationProcessor.java:276) ~[catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.util.DefaultAnnotationProcessor.processAnnotations(DefaultAnnotationProcessor.java:187) ~[catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1153) ~[catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026) ~[catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421) [catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734) [catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) [catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.StandardHost.start(StandardHost.java:840) [catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057) [catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463) [catalina-6.0.36.jar:6.0.36]
          at org.apache.catalina.startup.Embedded.start(Embedded.java:825) [catalina-6.0.36.jar:6.0.36]
          at org.red5.server.tomcat.TomcatLoader.init(TomcatLoader.java:517) [tomcatplugin-1.3.jar:na]
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_43]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_43]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_43]
          at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_43]
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java
  :1581) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522
  ) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Here is part of my Student.java and StudentEnrollmentServlet class.</p>
  
  <pre><code>@Named(Student.NAMED)
  public class Student {
  
  
      public static final String NAMED = "student";
  
      .......
  
  }
  
  @Named(StudentEnrollmentServlet.NAMED)
  public class StudentEnrollmentServlet extends HttpServlet {
  
      public static final String NAMED = "StudentEnrollmentServlet";
  
  
      @Resource(name = Student.NAMED)
      private Student student;
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
                       throws ServletException, IOException {
  
          processRequest(request, response);
      }
  
      .......
  }
  </code></pre>