Spring Framework Source code: Spring Beans's beanfactory

Source: Internet
Author: User

Let's get to know the class diagram of two important containers beanfactory and ApplicationContext:

Next, we introduce each of the classes that appear:

?? Public interface Beanfactory {string factory_bean_prefix = "&"; Object Getbean (string name) throws Beansexception; <T> T Getbean (String name, Class<t> requiredtype) throws beansexception;<t> T Getbean (class<t> Requiredtype) throws Beansexception;object Getbean (String name, Object ... args) throws beansexception;<t> T Getbean (class<t> requiredtype, Object ... args) throws Beansexception;boolean Containsbean (String name); Boolean Issingleton (string name) throws Nosuchbeandefinitionexception;boolean Isprototype (string name) throws Nosuchbeandefinitionexception;boolean Istypematch (String name, class<?> TargetType) throws Nosuchbeandefinitionexception; Class<?> GetType (String name) throws Nosuchbeandefinitionexception; String[] Getaliases (String name);}

Beanfactory base class, including the following members:

String Factory_bean_prefix = "&"; A constant member that is used to dereference a Factorybean instance, and to differentiate and Factorybean a series of beans that are created (the meaning of the dereference can refer to C + + programming

Thought a book, not here to introduce), such as a factorybean A, then get &a to get the factory instead of the bean instance.

Object Getbean (String name) throws Beansexception; Get a bean instance by name

<T> T Getbean (String name, Class<t> requiredtype) throws beansexception; A generic method that gets the bean instance by first name and class type class.

<T> T Getbean (class<t> requiredtype) throws beansexception; a generic method that gets the bean instance by class type.

Object Getbean (String name, Object ... args) throws beansexception; Create an instance by name and by displaying the arguments that are declared, and note that the arguments that show the declaration are used to create the prototype

<T> T Getbean (class<t> requiredtype, Object ... args) throws beansexception;

Boolean Containsbean (String name); Does the Bean factory contain a bean named name

Boolean Issingleton (String name) throws Nosuchbeandefinitionexception;bean is a singleton

Boolean isprototype (String name) throws Nosuchbeandefinitionexception;bean whether it is a prototype

Boolean Istypematch (String name, class<?> targetType) throws nosuchbeandefinitionexception; Whether the class type of the bean named name is TargetType

String[] Getaliases (String name); Gets all the dependencies for all beans, see Spring's configuration file

Next is one of its main two subinterfaces, hierarchicalbeanfactory, which is literally a layered bean factory, which, from the function interface provided, adds a channel to the parent container based on the beanfactory, but only gets (parent-child container, For example ApplicationContext is the parent container, Dispatcherservlet is a child container can be multiple, the child container can get to pay the container to access its contents, and vice versa):

Public interface Hierarchicalbeanfactory extends Beanfactory {beanfactory getparentbeanfactory (); Boolean Containslocalbean (String name);}

Beanfactory getparentbeanfactory (); Get parent container

Boolean Containslocalbean (String name); Determines whether the current container contains a bean named name and ignores the bean in the parent container.

The following is another important sub-interface listablebeanfactory for beanfactory:

Public interface Listablebeanfactory extends Beanfactory {boolean containsbeandefinition (String beanname); int Getbeandefinitioncount (); String[] Getbeandefinitionnames (); String[] Getbeannamesfortype (class<?> type); String[] Getbeannamesfortype (class<?> type, Boolean includenonsingletons, Boolean alloweagerinit);<t> Map <string, t> getbeansoftype (class<t> type) throws Beansexception;<t> map<string, T> Getbeansoftype (class<t> type, Boolean includenonsingletons, Boolean alloweagerinit) throws Beansexception; String[] Getbeannamesforannotation (class<? extends annotation> Annotationtype); Map<string, object> getbeanswithannotation (class<? extends Annotation> Annotationtype) throws Beansexception;<a extends annotation> A findannotationonbean (String beanname, class<a> annotationType) Throws Nosuchbeandefinitionexception;}

The official explanation is that this class is used to enumerate classes with XML definitions, such as XML-based beanfactory like Xmlbeanfactory. It only queries the beans created through the channel itself and ignores other channels (such as Hierarchicalbeanfactory).

Spring Framework Source code: Spring Beans's beanfactory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.