Spring manages bean containers (notes)

Source: Internet
Author: User

What is spring bean container? --- On the surface, it is a class + xml document, that is, the ApplicatonContext class and the spring configuration file beans. xml. We often write the following statement 12345 // instantiate spring container ApplicationContext ctx = new FileSystemXmlApplicationContext ("beans. xml "); // the file system is used to load the xml file. This is not the best method. We should use the class path to load the xml file, because different hosts have different file systems. // Obtain xx = ctx of a class. getBean ("XX id"); --- in essence, it uses the factory mode and the default Singleton mode to help us instantiate the bean we configured in xml and create the bean object, destruction and other lifecycle operations are carried out in a centralized place. If we want to use a bean, we will go to this place for retrieval.. The following <bean element. Copy the Code <? Xml version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id = "personDao" class = "cn. can. dao. personDao "/> <bean...> ..... </beans> the copy code is obvious. We configure our classes in the xml document, and then parse the xml document. This is an example of the parsing process. Here we should consider 1) How does spring create beans? What is its lifecycle? Load xml to parse xml. These beans are instantiated using the launch mechanism and the class describing the bean. Therefore, the default constructor of the bean is required. In this case, the factory is used to generate the class. In this factory, you only need to tell me that the class has the interface feature to get this class. 2) Is it a static factory instance or something else? Is this bean created using the singleton mode or prototype? What is the bean lifecycle? When will the instance be executed ?. When scope = "singleton" and lazy-init = 'default', the container is instantiated during loading, however, here lazy-init = 'true', the instantiation will be delayed. When scope = 'prototype', it is delayed instantiation.

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.