I just logged a bug in Spring bugsystem ( https://jira.springsource.org/browse/SPR-8551 ), but I'm still not sure if I missed something
I found a problem with <context:component-scan/> in this statement. Given the following two classes that are in the same JAR in the WEB-INF / lib web application (the JAR file has a directory structure):
Test / TheBean.java:
package test; @Component public class TheBean{ }
Test / BeanSearcher.java:
package test; public class BeanSearcher{ public void init(){ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.scan("test"); ctx.refresh(); TheBean b= ctx.getBean(TheBean.class);
If I run new BeanSearcher().init() in a jUnit test case or in another type of standalone application, b gets the assigned instance of TheBean, but if I run it, say in JSP, ctx.getBean() returns null.
So, I'm doing something wrong or not taking it into account, is this just a mistake ...?
EDIT 8/8/2011: it seems to work well, since I tried to simplify this problem, but still, when I try to get it to work, it fails when initializing OpenCms. Now I am trying to find the differences between working versions and what does not work. (Classloader, assignment of corresponding classes in different JARs or directly in WEB-INF / classes, calls through reflection, etc.)
source share