Spring container and management Bean's life cycle

Source: Internet
Author: User

In spring-based applications, application objects exist in the spring container, container objects create them, assemble them, configure them, manage their entire life cycle, from survival to death. The spring container uses dependency injection management to form the components of the application, and he creates an association between the components that are collaborating with each other.

The Sprin comes with a container implementation that can be categorized into two different types:

The 1.Bean factory (defined by the Org.springframework.beans.factory.BeanFactory interface) is the simplest container.

2. The application context (defined by the Org.springframework.context.ApplicationContext interface) is built on top of Beanfactory and provides application-oriented services.

The Bean factory is too low-level for most applications, so the context is more popular than the Bean factory.

Spring comes with the app context type:

1.classpathxmlapplicationcontext-loads the context definition from the XML configuration file under the Classpath and defines the application context as the file Action class resource;

2.FileSystemXmlapplicationContext---Read the XML configuration file under the file system and load the context definition;

3XmlWebApplicationContext---Read the XML configuration file under the Web application and load the context definition.

The difference between using Filesystemxmlapplicationcontext and using Classpathxmlapplicationcontext is that the former locates the configuration file under the specified file system path, The latter all of the classpath (including the jar file) find the configuration file.

Bean's life cycle:

Traditional Java applications are recycled by the Java automatic garbage collection mechanism, in contrast to the more delicate life cycle of the beans in the spring container. It is important to understand the life cycle of the spring bean correctly, because you might want to use the extension points provided by spring to customize the bean creation process. If the bean implements the Disposablebean interface, Spring will invoke its destroy interface method to destroy the bean.

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.