title: Component Scan not finding @Component's in a JAR in Tomcat webapp
body: <p>I just filed a bug in the Spring bugsystem ( <a href="https://jira.springsource.org/browse/SPR-8551" rel="noreferrer">https://jira.springsource.org/browse/SPR-8551</a> ), but I am still unsure if I am missing something</p>
  
  <p>I tracked down a problem with <code>&lt;context:component-scan/&gt;</code> to this statement.
  Given the two following classes which are in the same JAR in WEB-INF/lib of a web application (The JAR file has the directory structure):</p>
  
  <p>test/TheBean.java:</p>
  
  <pre><code>package test;
  @Component
  public class TheBean{
  }
  </code></pre>
  
  <p>test/BeanSearcher.java:</p>
  
  <pre><code>package test;
  public class BeanSearcher{
  
    public void init(){ 
      AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); 
      ctx.scan("test"); 
      ctx.refresh(); 
      TheBean b=  ctx.getBean(TheBean.class); 
      // What is the value of b? 
    }
  }
  </code></pre>
  
  <p>If I run <code>new BeanSearcher().init()</code> in a jUnit test case or other type of standalone application, b is getting assigned an instance of TheBean, but if I run it, say, in a JSP, <code>ctx.getBean()</code> is returning null.</p>
  
  <p>So, am I doing something wrong or not taking something into account, is this just a bug...?</p>
  
  <p>EDIT 8/8/2011: It seems to work good as I tried to simplify the problem, but still, when I try to make it work, in the initialization of OpenCms, it fails. Now I am trying to look for the differences between working versions and the one which doesn't work. (Classloader, ubication of the relevant classes in different JARs or directly in WEB-INF/classes, calls via reflection, etc.)</p>