Note that there are some explanatory texts on larger screens.

plurals
  1. POComponent Scan not finding @Component's in a JAR in Tomcat webapp
    primarykey
    data
    text
    <p>I just filed a bug in the Spring bugsystem ( <a href="https://jira.springsource.org/browse/SPR-8551" rel="nofollow">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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload