2011-08-07 3 views
0

アプリケーションコンテキストが既に初期化されているため、xml定義から別のBeanを追加する必要があります。xml定義から追加のBeanを既に初期化されているアプリケーションコンテキストに登録する

私はapplicationContext.getAutowireCapableBeanFactory()を実行できますが、これは単にObjectのプロパティをオートワイヤリングするためのものです。

XmlBeanDefinitionReaderとContextLoaderで表示する方法はわかりません。わかるように、公開メソッドのみがloadContext(String... locations)で、常に新しいコンテキストが作成されるためです。

あなたが親コンテキストの子としてあなたの作成したコンテキストを設定することで、あなたの2のApplicationContextを「マージ」と親を更新する必要が
public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { 
    if (logger.isDebugEnabled()) { 
     logger.debug("Loading ApplicationContext for locations [" + 
       StringUtils.arrayToCommaDelimitedString(locations) + "]."); 
    } 
    GenericApplicationContext context = new GenericApplicationContext(); 
    prepareContext(context); 
    customizeBeanFactory(context.getDefaultListableBeanFactory()); 
    createBeanDefinitionReader(context).loadBeanDefinitions(locations); 
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context); 
    customizeContext(context); 
    context.refresh(); 
    context.registerShutdownHook(); 
    return context; 
} 

答えて

-1

私が正しく、あなたが豆をロードすることを理解していればxmlの場所から既に存在するアプリケーションのコンテキストに移動します。あなたはちょうどこのafaikのように行く:

ApplicationContext context; 

    BeanDefinitionReader beanDefReader = new XmlBeanDefinitionReader(context) ; 
    beanDefReader.loadBeanDefinitions(locations); 
    context.refresh(); 
+0

私のためのコンポーネントのスキャンをしない – AbhishekAsh

5

GenericApplicationContext context = new GenericApplicationContext(); 
context.setParent(parentContext); 
parentContext.refresh(); 
関連する問題