アプリケーションコンテキストが既に初期化されているため、xml定義から別のBeanを追加する必要があります。xml定義から追加のBeanを既に初期化されているアプリケーションコンテキストに登録する
私はapplicationContext.getAutowireCapableBeanFactory()を実行できますが、これは単にObjectのプロパティをオートワイヤリングするためのものです。
XmlBeanDefinitionReaderとContextLoaderで表示する方法はわかりません。わかるように、公開メソッドのみがloadContext(String... locations)
で、常に新しいコンテキストが作成されるためです。
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;
}
私のためのコンポーネントのスキャンをしない – AbhishekAsh