How spring is managing beans

Source: Internet
Author: User

Often listen to the teacher say the container, what the container is. How it's reflected in spring. Have been puzzled, these two days to see the Spring Management Bean demo, the container in spring has a simple understanding.

We know that a container is a space concept that is generally understood as a place where objects can be filled. In spring containers are generally understood as beanfactory or ApplicationContext. We know that spring's IOC container can help us create objects, and we don't have to manually go to the new object after the object is given to spring management.

What is the difference between beanfactory and ApplicationContext?

Beanfactory employs a factory design pattern that reads bean configuration documents, manages bean loading, instantiates, maintains dependencies between beans, and is responsible for the bean's declaration cycle. In addition to providing the functionality provided by the above Beanfactory, ApplicationContext provides a more complete framework function: Internationalization support, AOP, transactions, etc. At the same time Beanfactory does not initialize the object when parsing the configuration file, the object is initialized only with Object Getbean (), and ApplicationContext initializes all objects in the configuration file when the configuration file is parsed, Getbean ( ) method is just the process of getting an object.

So we usually use applicationcontext when we use it.

ApplicationContext is how to manage beans. The following demo is a simple imitation of this principle:

1. Create a class Personservicebean and configure it in the XML file.

[Java] view plain copy public class Personservicebean implements Personservice {public void Save () {       System.out.println ("I Am the Save () method"); }} [HTML] view plain copy <bean id= "Personservice" class= "Cn.itcast.service.impl.PersonServiceBean" &G T;</bean>

2. Create a class beandefinition that provides a constructor that acts as a public transformation class for each bean.

[Java]  View Plain  copy   public class beandefinition {               private String id;          private String className;               public beandefinition (string id, string classname)  {            this.id = id;            this.className = className;       }           public string getid ()  {            return id;       }           public void setid (string id)  {            this.id = id;       }           Public string getclassname ()  {            return classname;       }           Public void setclassname (string classname)  {            this.className = className;       }  }   

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.