1

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);
}

私のapplicationContextから:

<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

なぜうまくいかないのか分かりますか?

ありがとう。

4

2 に答える 2

2

この行ではありません

innerContext.registerSingleton("beanName", FixSessionBean.class);

-parameterの値ではなく、名前「beanName」でBeanを登録しますbeanNameか?おそらく、代わりにパラメータを使用するつもりでした。

于 2012-07-09T10:16:33.620 に答える
0

Bean クラス名を取得する場合は、 Bean クラス名を渡す必要FixSessionBean.classがあります。投稿したのが appctx だけの場合、mm1 は定義されていません。

于 2012-07-09T10:13:10.883 に答える