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.