有很多方法可以做到这一点。最好的参考在这里:
http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#context-
introduction
您需要查看的特定类是SingletonBeanFactoryLocator和ContextSingletonBeanFactoryLocator。
如果使用SingletonBeanFactoryLocator,则可以使用以下内容查找bean:
BeanFactoryLocator bfl = SingletonBeanFactoryLocator.getInstance();BeanFactoryReference bf = bfl.useBeanFactory("com.mycompany.myapp");MyClass zed = bf.getFactory().getBean("mybean");Javadocs中对此有很好的详细解释:
http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/factory/access/SingletonBeanFactoryLocator.html
另外,为了清楚起见,请确保配置文件位于应用程序的类路径中,否则查找将失败。



