简体   繁体   English

spring 如何从应用程序上下文中获取 BeanFactory

[英]spring how to get BeanFactory from Application Context

I am a beginner in spring.我是 spring 的初学者。 Today, when I was reading the spring core document, I found the following instructions in chapter 1.3.今天在阅读spring核心文档的时候,发现1.3章有如下说明。 Bean Overview 豆概述

In addition to bean definitions that contain information on how to create a specific bean, the ApplicationContext implementations also permit the registration of existing objects that are created outside the container (by users).除了包含有关如何创建特定 bean 的信息的 bean 定义之外,ApplicationContext 实现还允许注册在容器外部(由用户)创建的现有对象。 This is done by accessing the ApplicationContext's BeanFactory through the getBeanFactory() method, which returns the BeanFactory DefaultListableBeanFactory implementation.这是通过 getBeanFactory() 方法访问 ApplicationContext 的 BeanFactory 来完成的,该方法返回 BeanFactory DefaultListableBeanFactory 实现。 DefaultListableBeanFactory supports this registration through the registerSingleton(..) and registerBeanDefinition(..) methods. DefaultListableBeanFactory 通过 registerSingleton(..) 和 registerBeanDefinition(..) 方法支持这种注册。 However, typical applications work solely with beans defined through regular bean definition metadata.但是,典型的应用程序仅使用通过常规 bean 定义元数据定义的 bean。

I instantiated an ApplicationContext object in IDEA with the following code, but I found that this object does not have a getBeanFactory() method:我用下面的代码在IDEA中实例化了一个ApplicationContext object,但是我发现这个object没有getBeanFactory()方法:

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("test.xml");

The document I read is the 5.3.5 version of spring, and I am using the same version of spring.我看的文档是5.3.5版本的spring,我用的是同版本的spring。

I guess if spring changed the ApplicationContext class and forgot to modify the document.我猜如果 spring 更改了 ApplicationContext class 并忘记修改文档。 Or is there something wrong with the object I instantiated?还是我实例化的 object 有问题?

Thanks in advance!提前致谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring BeanFactory作为Swing应用程序中的单例 - Spring BeanFactory as a singleton in a Swing application 如何在Spring IOC中设置当前beanFactory的父级 - How to set parent of current beanFactory in spring IOC Struts 2 和 Spring 4,如何从 spring 应用程序上下文中获取验证器或动作对象 - Struts 2 and Spring 4, how to get the validator or action object from spring application context 在ServletContextListener上获取Spring应用程序上下文 - Get spring application context on a ServletContextListener 如何从 maven 模块获取 spring 上下文 - How to get spring context from maven module Spring:如何从实现通用接口的应用程序上下文中获取bean? - Spring: how to get bean from application context which implements generic interface? 从另一个portlet获取Portlet应用程序上下文(Liferay + Spring) - Get Portlet Application Context from another portlet (Liferay + Spring) 从groovy类中的应用程序上下文中获取spring bean - Get spring bean from application context in groovy class 从Spring安全上下文访问应用程序上下文 - Access application context from spring securty context 来自 Spring 应用程序上下文的 Servlet 上下文属性 - Servlet context attribute from Spring application context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM