我正在使用 Spring3.1
我以编程方式注册了一个 Bean,我也想以编程方式检索它,但没有成功。
public void createBean(String beanName, String beanParam) {
System.out.println("beanName=" + beanName + " beanParam=" + beanParam);
ApplicationContext context = ApplicationContextSingleton.getApplicationContext();
StaticApplicationContext innerContext;= new StaticApplicationContext(context);
innerContext.registerSingleton("beanName", FixSessionBean.class);
configureBean(innerContext, beanName, beanParam);
}
public void configureBean(ApplicationContext innerContext, String beanName, String beanParam) {
innerContext.getBean(beanName);
FixSessionBean fixSessionBean = (FixSessionBean) innerContext.getBean(beanName);
}
从我的应用程序上下文中:
<bean id="FixSessionBean" class="com.finbird.fixgw.beans.FixSessionBean" />
这是一些日志证据:
beanName=mm1 beanParam=mm2
2012-07-09 13:07:31,016 com.fixgw.test.TriggerBean [ERROR] org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mm1' is defined
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mm1' is defined
知道为什么进展不顺利吗?
谢谢。